Jump to content


Photo

mysql question


  • Please log in to reply
3 replies to this topic

#1 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 23 October 2006 - 12:06 AM

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:
$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);
Ignore $query2 thats just there to add the search information into the database

#2 Design

Design
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationThe Computer Chair

Posted 23 October 2006 - 12:09 AM

use %'s as wildcard characters around and between the search criteria

#3 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 23 October 2006 - 12:24 AM

i have havnt i?
'%".$searchterm."%'


#4 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 23 October 2006 - 10:19 AM

anyhelp?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users