Jump to content

Order By Most Mutual Friends


ueon

Recommended Posts

How Do I output the following?

 

1) Search a name

2) Output all users on network with most mutual friends listed at the top

 

*** The $mutualfriends query works, but I have no idea on $friendoutput

 

$Mutualfriends = "SELECT * FROM addfriend WHERE ((request='$you' AND receive='$friend') AND confirm='2') OR ((request='$friend' AND receive='$you') AND confirm='2'"

 

$friendoutput = "SELECT * FROM users WHERE Username LIKE '%$user%' ORDER BY $mutualfriends DESC

Link to comment
https://forums.phpfreaks.com/topic/250183-order-by-most-mutual-friends/
Share on other sites

I'm making a social network right now - the search function specifically. I have no idea how to write a mysql query that would do the following:

 

For example, if I search for "John" on the social network, it would return all "John"s on the network. I would like to rank the output by listing the "John" with the most mutual friends with me first.

 

1) John - 30 mutual friends

2) John - 20 Mutual friends

3) John - 10 mutual friends

 

$Mutualfriends = "SELECT COUNT(*) FROM addfriend WHERE ((request='$you' AND receive='$friend') AND confirm='2') OR ((request='$friend' AND receive='$you') AND confirm='2'"

 

So the above query returns the number of mutual friends you have with this user. And the following query is trying to order all users in the database with the most mutual friends at the top

 

$friendoutput = "SELECT * FROM users WHERE Username LIKE '%$username%' ORDER BY $mutualfriends DESC

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.