+ 1

How to sort mysql search results

I wrote a simple mysql query for search my db for usernames and their fullname but i dont know how to sort the result based on their relevance like how its done on instagram. This is my original query $search is the search string var SELECT username,fullname from users WHERE username LIKE '%$search%' or fullname LIKE '%$search%' I would greatly appreciate any help. Thanks in advance 😀

4th Mar 2017, 10:33 AM
Chinemerem Nworisa
Chinemerem Nworisa - avatar
5 odpowiedzi
+ 2
will try that nd give u feedback
4th Mar 2017, 12:45 PM
Chinemerem Nworisa
Chinemerem Nworisa - avatar
+ 1
Whichever is more important. if fullname is more important then it should be ORDER BY fullname asc, username asc I suggest you should set a LIMIT so it doesn't give you a long list. LIMIT 10
4th Mar 2017, 12:48 PM
Joshua Oducado
Joshua Oducado - avatar
0
What do you mean by relevance? What ouput are you after?
4th Mar 2017, 10:35 AM
Joshua Oducado
Joshua Oducado - avatar
0
i want it to be ordered based on the amount similarities between the words
4th Mar 2017, 12:40 PM
Chinemerem Nworisa
Chinemerem Nworisa - avatar
0
ORDER BY username asc, fullname asc
4th Mar 2017, 12:43 PM
Joshua Oducado
Joshua Oducado - avatar