graham23s Posted August 15, 2007 Share Posted August 15, 2007 Hi Guys, in my search if i do 1 word say: graham it searches and find it ok but if there is characters in between them say graham-another word.another word the characters after the work seem to bring back no results basically i just need to search the word graham to get results the minute i put 2 or more words together the reults bring back nothing is there a way to be able to search multiple words? code: part of the query $search_query .= "WHERE (`file_name` LIKE '%$keywords%' OR `file_name` LIKE '%$keywords%')"; cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/65102-search-function/ Share on other sites More sharing options...
JoeyT2007 Posted August 15, 2007 Share Posted August 15, 2007 I would do: (index.php?search=Search%20Function) $keywords=$_GET['search']; $keywords=trim($keywords); $result=mysql_query("SELECT * FROM $table WHERE words LIKE '$keywords'); $num=mysql_numrows($result); echo "Results: $num"; while($results=mysql_fetch_array($result)) { print "<tr class='alt'><td><a href='URL'>$results[FIELD]</a></td></tr>"; } etc... I'm not very good at PHP so i'm probably wrong, but hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324918 Share on other sites More sharing options...
php_tom Posted August 15, 2007 Share Posted August 15, 2007 Split the keyword string into a word array by using PHP's strtok() or explode(). Then like so: <?php // Say the words are in $keyword_array... $search_query = "WHERE ("; for($i=0;$i<count($keyword_array)-1;$i++) $search_query .= "'file_name' LIKE '%".$keyword_array[$i]."%' "; $search_query .= "'file_name' LIKE '%".$keyword_array[count($keyword_array)-1]."%')"; ?> Hope that helps. Note: The code in the post above is BAD for security!!! Quote Link to comment https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324923 Share on other sites More sharing options...
graham23s Posted August 15, 2007 Author Share Posted August 15, 2007 Hi Guys, yeah it searches for 1 word in the string but not multiple hello_there it will only find hello or there hello there this is fine no _ or any other characters confusing it it will find all this cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.