Renlok Posted October 23, 2006 Share Posted October 23, 2006 i have a search bar which searches my database but at the moment it will only return matches with the exact results how can i have it so say you search for php freaks it will show results with php and freaks anywere instead of php freaks being two words next to each other.Current code:[code]$searchterm=$_POST['searchterm'];$searchtype=$_POST['searchtype'];$searchterm= trim($searchterm);$searchtype= trim($searchtype);if (!$searchterm){echo 'You have not entered search details. Please go back and try again.';exit;}if (!get_magic_quotes_gpc()){$searchtype = addslashes($searchtype);$searchterm = addslashes($searchterm);}$date = date('Y-m-d'); $query2 = "insert into search(searchterm, dateadded) values ('".$searchterm."', '".$date."')"; $result2 = $db->query($query2) or die ($db->error); $query = "select * from link where ".$searchtype." like '%".$searchterm."%'";$result = $db->query($query);[/code]Ignore $query2 thats just there to add the search information into the database Quote Link to comment Share on other sites More sharing options...
Design Posted October 23, 2006 Share Posted October 23, 2006 use %'s as wildcard characters around and between the search criteria Quote Link to comment Share on other sites More sharing options...
Renlok Posted October 23, 2006 Author Share Posted October 23, 2006 i have havnt i?[code]'%".$searchterm."%'[/code] Quote Link to comment Share on other sites More sharing options...
Renlok Posted October 23, 2006 Author Share Posted October 23, 2006 anyhelp? Quote Link to comment 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.