Jump to content

mysq search criteria problem


neilfurry

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.