I’m using the following query to select users from my ‘users’ table with the logged-in user’s session id here being $uid:
SELECT first_name, last_name, uid, hometown from users where concat(first_name,' ',last_name) like '%$q%' and uid <> $uid LIMIT 6
I also use the following query to select all of the user’s friends from the ‘friends’ table:
SELECT a.first_name, a.uid, a.last_name FROM users a, friends b WHERE a.uid = b.friend_two AND b.friend_one = $uid
My question is how would I order such a query with the friend’s users at the top? So for example, if my user searches ‘Dave’ and I return 5 people with the first name, Dave, how can I rank his friend Dave on top of all the other Daves and order the query in such a manner?
Thanks for any help.
Try this: