Jump to content

Archived

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

Renlok

mysql question

Recommended Posts

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

Share this post


Link to post
Share on other sites
use %'s as wildcard characters around and between the search criteria

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.