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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyword Search for multiple words

Status
Not open for further replies.

Keendev

Technical User
Jan 23, 2006
106
PH
Hi,

I just made a keyword search into my dynamic site and is working just fine for a one word

Problem is if I search for "rich famous" word..my search result doesn't return any. But if I search for "rich" or "famous" only... my search page return a result.

need help on this..

thanks a lot.
 
you need to do something like this

Code:
$column = 'fieldName';
$keywords = explode(" ", $_POST['keywords']);
foreach ($keywords as &$kw){
 $kw = "$column like '%".mysql_escape_string($kw)."%'";
}
$query = "Select * from table where ".implode(" OR ", $keywords);

this assumes a free text keywords search. you should make sure that you have an FT index on this column.

if you use proper keyword tagging you will store the keywords in a join table. in which case you should use an IN comparison rather than a like. the format is different but the process is the same as that posted above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top