ueon Posted October 31, 2011 Share Posted October 31, 2011 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted November 1, 2011 Share Posted November 1, 2011 Huh? Quote Link to comment Share on other sites More sharing options...
ueon Posted November 2, 2011 Author Share Posted November 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2011 Share Posted November 2, 2011 Well, you'll need to run that count(*) from each username -- which I assume is $you in the first query? Quote Link to comment Share on other sites More sharing options...
ueon Posted November 2, 2011 Author Share Posted November 2, 2011 sorry, but would it be possible to write the query? I have no idea how to use the two queries together with count Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2011 Share Posted November 2, 2011 Well, you need to tell me how $you, $friend and $username are related first. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.