Jump to content

mysql question


Renlok

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.