Lakshmi Posted August 7, 2007 Share Posted August 7, 2007 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 More sharing options...
justsomeguy Posted August 7, 2007 Share Posted August 7, 2007 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 More sharing options...
Lakshmi Posted August 7, 2007 Author Share Posted August 7, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.