Welcome Guest, Not a member yet? Register   Sign In
all ideas welcome... interesting db foreign keys question - hierarchy database stuff
#1

[eluser]september28[/eluser]
Hi there,

So i have a table called "links" which basically has 5 columns: id, ex1, ex2, user, date.

now ex1 and ex2 actually relate to the id of a record in another table (called "explanations"). Therefore "links" is simply a linking table between 2 records in the explanations table.

Now, I will try my best to explain what i want to do....

The user can add a link by identifying the 2 records in the explanations table, therefore if 2 records have ids of 23 and 45 then the links table will basically look like this:
ex1 = 23, ex2 = 45, user = 3, date = 07/05/09

now, Basically what i want my controller to do is find all of the links that a particular explanation is involved in so e.g. a user browses to explanation id 23. on the page are displayed the links that this explanation has (in this case only 45 but could be more). So far everything is easy - just take the explanation id that the user called and select in the links table based on ex1 OR ex2 = 23.

Now, here is the tricky bit, I then want my controller to take the linked explanation id (in this case 45) and then search the table for any links with 45 (minus of course the original one with 23). If it finds any, I want the process to be repeated again and again until no more links are found. so eg 45 might be linked to 12 and also 67, so then the process should be repeated with these numbers (12 and 67) until no more links are found. The reason That i want to do this is so that linking can grow exponentially (my application is like a dictionary where users can link meanings of words thus creating synonyms) therefore i am presuming that if 23 links with 45, then 23 should also link with whatever else 45 links with and so on.

Visually this takes the form of a spider diagram (it is a lot easier to visualise than to explain).

In the end, the controller function should then return an array for the view of all the links (so in this case [45,12,67 etc...]

Does anyone have any ideas how this could possibly be achieved or indeed whether i am making any sense at all?

Thanks in advance,

Dan


Messages In This Thread
all ideas welcome... interesting db foreign keys question - hierarchy database stuff - by El Forum - 05-07-2009, 08:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB