Greetings all,
I'm building a community based website for a client, but they've asked me to create something which i'm not sure on how to go about doing...
Basically, you create friends on this website. These details are stored in two tables...
User
User ID
First Name
Last Name
etc..
Friends
Link ID
User ID 1
User ID 2
Easy enough so far!
The client has asked me to build a feature specifying the following:
When the user clicks on another user's profile, and they're not directly friends, work out if they know any of your other friends, to calculate the chance that you might know them..
So for example...
Rich is friends with Phil, and Phil is friends with Dan. However, Rich is not currently friends with Dan. When Rich goes on Dan's profile, it needs to go through all Rich's friends, to see if they know Dan. The theory is, it should find that Phil is friends with Dan.
Now I can do this using PHP, no problem. My idea was to have a loop, and just go through each one of Rich's friends, running an SQL query to see if they know Dan. However, a query per user... if Rich has 400 friends, that is not exactly an ideal solution.
Is there a way of doing this using 1 SQL query, or another way of doing it efficiently?
Any thoughts would be hugely appreciated!
I'm building a community based website for a client, but they've asked me to create something which i'm not sure on how to go about doing...
Basically, you create friends on this website. These details are stored in two tables...
User
User ID
First Name
Last Name
etc..
Friends
Link ID
User ID 1
User ID 2
Easy enough so far!
The client has asked me to build a feature specifying the following:
When the user clicks on another user's profile, and they're not directly friends, work out if they know any of your other friends, to calculate the chance that you might know them..
So for example...
Rich is friends with Phil, and Phil is friends with Dan. However, Rich is not currently friends with Dan. When Rich goes on Dan's profile, it needs to go through all Rich's friends, to see if they know Dan. The theory is, it should find that Phil is friends with Dan.
Now I can do this using PHP, no problem. My idea was to have a loop, and just go through each one of Rich's friends, running an SQL query to see if they know Dan. However, a query per user... if Rich has 400 friends, that is not exactly an ideal solution.
Is there a way of doing this using 1 SQL query, or another way of doing it efficiently?
Any thoughts would be hugely appreciated!
