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 Search

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
I have made a search using LIKE syntax but my problem is if my field has more than one word in it, I can't match against the other words in the field only if the search string exactlly matches the word set

How do I overcome this?? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
I have managed to do it by spliting the field up using preg_split() and looping through matches etc Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
try this:

$words=explode(" ",$search);

while(list($index,$value)=each($words)){
if (strlen($value)>2){
$words[$index]="text like '%$value%'";
}
}
reset($words);
$query="SELECT ... WHERE text like '%$search%' or ".implode(" or ",$words)." ORDER BY ... ";
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top