Okay, I'm making a database driven website using Mysql and PHP in which I connect people to other people.
Now supose I have:
TABLE: people FIELDS: ID, Person
TABLE: connect FIELDS: person_ID, Connection_ID
The data in the TABLE: people... would be something like:
1, Bob - 2, John - 3, Ben
The data in the TABLE: connect... would be something like:
1, 2 - 2, 3
meaning that Bob is connected to John and John is connected to Ben.
Now, suppose I want to connect a person to all his connections and all his connections to all their connections... it would look something like this... right?
SELECT p1.Person, p2.Person, p3.Person FROM people AS p1, connect AS c1, people AS p2, connect AS c2, people AS p3 WHERE p1.ID=c1.person_ID AND c1.Connection_ID=p2.ID AND p2.ID=c2.person_ID AND c2.Connection_ID=p3.ID
But what if I wanted to keep going... as in... List a person AND all the people he's connected to... AND all the people THOSE people are connected to... AND all the people THOSE people are connected to... etc. etc.
would I have to keep adding p1,p2,p3,p4,p5 and c1,c2,c3 and so on... or is their a way to make it repeat it on it's own?
infinite joins... can this be done?
Moderator: General Moderators