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 Link to comment https://forums.phpfreaks.com/topic/24788-mysql-question/ 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 Link to comment https://forums.phpfreaks.com/topic/24788-mysql-question/#findComment-112886 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] Link to comment https://forums.phpfreaks.com/topic/24788-mysql-question/#findComment-112893 Share on other sites More sharing options...
Renlok Posted October 23, 2006 Author Share Posted October 23, 2006 anyhelp? Link to comment https://forums.phpfreaks.com/topic/24788-mysql-question/#findComment-113056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.