Jump to content

Search


Lakshmi

Recommended Posts

Hii'm getting small problem in searching the words.For examplei stored some degree colleges names (Ex:xyz degree college,..) in my dabase.if i searching with "Degree Colleges" ,i'm not getting any resultif i search with "Degree College" i'm getting the results. if any word match with degree or college or both words i need the resultsHow t o search using mysql,phpThanks for any help.Lakshmi

Link to comment
Share on other sites

You would need to split up the search term into each word and then loop through them and build your query.

$words = explode(" ", $search_term);$sql = "";foreach ($words as $word){  if ($sql != "")	$sql .= " OR ";  $sql .= "field_name LIKE '%" . mysql_real_escape_string($word) . "%'";}if ($sql != ""){  $sql = "SELECT * FROM table WHERE " . $sql;  $results = mysql_query($sql);}

Link to comment
Share on other sites

Thanks for your help.

You would need to split up the search term into each word and then loop through them and build your query.
$words = explode(" ", $search_term);$sql = "";foreach ($words as $word){  if ($sql != "")	$sql .= " OR ";  $sql .= "field_name LIKE '%" . mysql_real_escape_string($word) . "%'";}if ($sql != ""){  $sql = "SELECT * FROM table WHERE " . $sql;  $results = mysql_query($sql);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...