Amish_Geek
01-06-2006, 11:42 PM
I'm trying to create a query to extract a 2nd layer of "friendship" from a table.
I have a table with the followin structure.
[f_id][u_id][f_u_id]
f_id = primary key, auto increment. This is the "Friend Entry ID"
u_id = Users userID
f_u_id = Friend of User userID
Right now, the query:
Select * from friends where u_id=$u_id;
Will return all "Friends" of the user with the userid $u_id.
I want to have a query that will return a 2nd level of friendship. IE the friends of the users friends.
I could do a php loop,
Select * from friends where u_id=$u_id
for each $u_id { select * from friends where u_id = $u_id }
But that would be a LOT of database queries and would slow things down. I remember from my Database management class that there is a way to do somethign similar to this, but I can't remember how.
Any help?
I have a table with the followin structure.
[f_id][u_id][f_u_id]
f_id = primary key, auto increment. This is the "Friend Entry ID"
u_id = Users userID
f_u_id = Friend of User userID
Right now, the query:
Select * from friends where u_id=$u_id;
Will return all "Friends" of the user with the userid $u_id.
I want to have a query that will return a 2nd level of friendship. IE the friends of the users friends.
I could do a php loop,
Select * from friends where u_id=$u_id
for each $u_id { select * from friends where u_id = $u_id }
But that would be a LOT of database queries and would slow things down. I remember from my Database management class that there is a way to do somethign similar to this, but I can't remember how.
Any help?
