What I am trying to do: Multi word search, and when the user selects pub from the drop down it needs to only retrieve records where pub is not equal to ‘-‘ in the table.
What’s going wrong: It does some filtering but the last record is a record with a ‘-‘
What I have tried:
I’ve tried the following query in the MySQL console.
My query:
SELECT * FROM ticker where pub <> '-' AND (summary LIKE '%funny%' OR cust_exp LIKE '%funny%') OR (summary LIKE '%joke%' OR cust_exp LIKE '%joke%') OR (summary LIKE '%impact%' OR cust_exp LIKE '%impact%') ORDER BY `created` DESC
The above query is generated via:
constructing the multi-word search..
$words = explode(" ",$keywords);
$queryWords = '';
$i=0;
foreach($words as $each){
$i++;
if ($i == 1){
$queryWords.=" (summary LIKE '%$each%' OR cust_exp LIKE '%$each%') ";
}
else{
$queryWords.=" OR (summary LIKE '%$each%' OR cust_exp LIKE '%$each%') ";
}
}
snippet of query code..
elseif ($ticket_type == 'Pub'){
if ($status == 'All'){
if (empty($product)){
$query="SELECT * FROM ticker where pub <> '-' AND".$queryWords."ORDER BY `$order_by` DESC";
}
EDIT: Sample search string is ‘funny joke impact’
Try this: