2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by drewpark88
1

get an array of keywords from the textbox -

$raw = $_POST['keyword'];
$clean = trim(mysql_real_escape_string($raw));
$k_array = explode(" ", $clean); //assuming space is the separator

//this needs more tests - but gives you an idea
$clause = "WHERE ";
$i = 0;
foreach($k_array as $word){
  if($i > 0)$clause .= " OR ";
  $clause .= "field1 LIKE '%$word%'";
  $i = $i + 1;
}

$query = mysql_query("SELECT field1,field2 FROM table1 $clause");

Top of my head, not tested, sure there's a more efficient way too.

Votes + Comments
Ardav gives helpful responses : )
0

Thanks I will try this : )

get an array of keywords from the textbox -

$raw = $_POST['keyword'];
$clean = trim(mysql_real_escape_string($raw));
$k_array = explode(" ", $clean); //assuming space is the separator

//this needs more tests - but gives you an idea
$clause = "WHERE ";
$i = 0;
foreach($k_array as $word){
  if($i > 0)$clause .= " OR ";
  $clause .= "field1 LIKE '%$word%'";
  $i = $i + 1;
}

$query = mysql_query("SELECT field1,field2 FROM table1 $clause");

Top of my head, not tested, sure there's a more efficient way too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.