Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL LIKE Question??? 1

Status
Not open for further replies.

Actorial

Programmer
Aug 23, 2006
38
US
Hi There,

I am trying to a database search for something using

LIKE '%$something%'

It works fine for one word like if I search "elephant" it returns the rows with "elephant"

BUT, if I search "blue elephant" it only returns rows with the string "blue elephant" and not just "elephant". What I want is when I search "blue elephant" for mySQL to return all results with "blue" or "elephant" in them.

I know I could probably do this with some PHP code, but was wondering if there is a beter way with mySQL?

Thank You in Advance!
 
The simplest way would be:[tt]
WHERE fldname LIKE '%elephant%' OR fldname LIKE '%blue%'[/tt]

This will return all records where the field contains either of those strings. In other words, "elephantiasis" will be recognised, as will "blueberry".

If you want to have functionality similar to web-search engines, where words are recognised, then your field would need to have a full-text index declared for it, and you would use the MATCH function to search for words. This system is described in the MySQL manual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top