I have a table of users of a website which can be searched for in a search box. I want to sort the users so that mutual friends would appear first.
The 'Users' table looks like this:
ID | Name
----------------
24 | John Smith
25 | Tom Jones
and the 'Friends' table looks like this:
ID | Sender | Recipient | accepted
-----------------------------------
01 | 24 | 25 | True
So say I was friends with John Smith and I searched for Tom Jones, the Tom Jones with ID 25 would appear first as he is a mutual friend of mine.
I'm not sure how to go about this, I'm guessing I would have to check the ID of all the Tom Jones' and then check if they are in the 'Friends' table, if they are and if the sender is an accepted friend of mine then they are a mutual friend.
Though it is not necessary, it would be nice to have a count of all the mutual friends, though I'm not sure if that is too complex.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire