I am trying to create a simple search on my website (this is a social network site), and I want to search for all users registered on the website and return a list of offers (why this request is needed, a list of offers).
There are columns in my table that I want to find: userID , fname , lname .
I want to search the last 2 columns (2 names) and return them in order of how many names match the search query.
The first part of the query that I would run would be the following:
SELECT userID, fname, lname FROM names WHERE
but otherwise I need help.
EDIT: using this query to search:
SELECT userID, fname, lname FROM names WHERE fname LIKE '%".$term."%' OR lname LIKE '%".$term."%'
How can I order it so that the results are sorted by those that match at the beginning, so when I type M , it returns say, Mark to adam
source share