Thanks Nathan.
The MySQL Match/Against will probably work well... but I would need to somehow add a "+" to the beginning of each word in the phrase so PHP will still be involved.


On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:

Rick Dwyer wrote:
Hello all.
I have a page where the user can enter a search phrase and upon submitting, the search phrase is queried in MySQL. However, I need to modify is so each word in the phrase is searched for... not just the exact phrase.
So, "big blue hat" will return results like:
"A big hat - blue in color"
"Hat - blue, big"
SQL would look like ....
WHERE (item_description like "%big%" and item_description like "%blue%" and item_description like "%hat%" )

You may be better to use full text and MATCH for this, see:


So, via PHP, what is the best way to extract each word from the search phrase to it's own variable so I can place them dynamically into the SQL statement.

There are many ways you can do this:

Many examples can be found on the above pages, and you're real solution depends on how many edge-cases you want to cover, but the above will cover most approaches :)



PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to