PHP SQL Search query matching -


i have search page in php uses following query fetch content database.

select * linkbase (`title` '%".$s."%') or (`descr` '%".$s."%') 

here how db looks :

id  |title         |descr ----------------------------------------- 1   |hello world   |this hello world description 2   |piedpiper     |the silicon valley company piedpiper 3   |stackoverflow |ask questions on programming 

now, example, if run query value of $s = "silicon valley", fetches row 2. fine. if user enters search term silicon piedpiper. returns no results above sql query. how can modify query in such way return row 2 second search term too.

question summery : how can search query using php , sql in such way result returned if the user enters 2 words not placed consequent each other in db

if need support arbitrary order of words in search suggest using regexp mysql function simple "or" regular expression like

select * linkbase (`title` regexp 'silicon|piedpiper') or (`descr` regexp 'silicon|piedpiper') 

so can replace whitespace php , replace them pipe symbol (|) , order of words don't matter anymore.

this select rows contain @ least 1 of words, if need match words in list regular expression might necessary.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -