php - MySQL: Query to Search All possible words -


i have form input box user can specify names, names can 2 or more words eg john smith or john michael smith.

i need write query return records including words in submitted name. query return records has name words can have different order.

for example, if search string john michael smith, query should able return records names such john smith michael, michael smith john, smith john michael or other combination words there. can seen return records still has words in name field can have different order. should not return results not contain name part example john michael should not returned since missing smith.

i can't figure out how write query such requirement have. please help.


update

the answers provided far return records match john michael also. tried answers of @marco, @abesto , @eddie.

the problem still persists :(

you try fulltext search:

select * table match (name) against ('+part1 +part2 +part3' in boolean mode); 

in solution, '+part1 +part2 +part3' generated in php.

see the mysql docs

mysql> select * sof; +--------------------+ | n                  | +--------------------+ | john               | | smith              | | smith john         | | smith john michael | | john               | +--------------------+ 5 rows in set (0.00 sec)  mysql> select * sof match(n) against('+john +smith +michael' in boolean mode); +--------------------+ | n                  | +--------------------+ | smith john michael | +--------------------+ 1 row in set (0.00 sec) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -