neilfurry Posted January 13, 2016 Share Posted January 13, 2016 hello mate, im having problem making a search criteria work.... i have a field named fullname, inside that field i have a data eg: "Robert Williams" Im trying to use LIKE on mysql statement such as SELECT fullname FROM clients WHERE fullname LIKE '%keyword%' keyword being any character from the name "Robert Williams". but when i tried to search "Williams R" it will not show me "Robert Williams"... Then, how can i make it so that when i search for "Williams R" it will also show me "Robert Williams" What im trying to attain here is to search any name in any order whether firstname first of lastname first. Thank you in advance. Cheers! Neil Quote Link to comment Share on other sites More sharing options...
requinix Posted January 13, 2016 Share Posted January 13, 2016 a) Instead of using fullname LIKE "%Williams R%" make it do fullname LIKE "%Williams%" AND fullname LIKE "%R%". b) If the search has two "words" make it do fullname LIKE "%Williams%R%" OR fullname LIKE "%R%Williams%". Three would probably "Last F M" so that would be OR fullname LIKE "%F%M%Last%". That lone "R" sucks. Quote Link to comment Share on other sites More sharing options...
neilfurry Posted January 13, 2016 Author Share Posted January 13, 2016 a) Instead of using fullname LIKE "%Williams R%" make it do fullname LIKE "%Williams%" AND fullname LIKE "%R%". b) If the search has two "words" make it do fullname LIKE "%Williams%R%" OR fullname LIKE "%R%Williams%". Three would probably "Last F M" so that would be OR fullname LIKE "%F%M%Last%". That lone "R" sucks. note that this search query can be another name not just Williams Robert... so that should be $keyword sent via $_REQUEST method Quote Link to comment Share on other sites More sharing options...
neilfurry Posted January 13, 2016 Author Share Posted January 13, 2016 so for example: $keyword ="" When i search using the following query: SELECT fullname FROM clients WHERE fullname LIKE '%".$keyword."%' if i have John Doe on my clients table and i want to search Doe Jo... it should also return the name John Doe... as the search $keyword name is just a reverse of the fullname. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 13, 2016 Share Posted January 13, 2016 Yeah... I didn't mean for you to put literally "Williams R" in the query. It was an example. 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.