BrighteyesDesign
asked on
Search function not displaying results for both names
I have a search function where you can search someones name. The first name and surname are in different database columns so i'm using this...
WHERE fname LIKE '%$search%' OR lname LIKE '%$search%'
It's not working though. Say for example 'John Smith' is one of the searchable names. If you search 'John' or 'Smith' he displays for if you search 'John Smith' he doesn't.
Any idea how I can get this too work?
WHERE fname LIKE '%$search%' OR lname LIKE '%$search%'
It's not working though. Say for example 'John Smith' is one of the searchable names. If you search 'John' or 'Smith' he displays for if you search 'John Smith' he doesn't.
Any idea how I can get this too work?
what you have to do is 1st remove the space from your search string then concat the two fields and do a like search.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another possibility...
WHERE fname LIKE '%$search%' OR lname LIKE '%$search%' OR CONCAT(fname,' ',lname) LIKE '%$search%'
WHERE fname LIKE '%$search%' OR lname LIKE '%$search%' OR CONCAT(fname,' ',lname) LIKE '%$search%'