Reputation: 4546
I am trying to get this query right
foreach(explode(" ", trim($words) ) as $word) $where[] = "LIKE '%$word%'";
$wheresql = implode(" OR ", $where);
$q = "SELECT item_id, name, price, details, img FROM items WHERE (details $wheresql) OR (name $wheresql) OR (description $wheresql)";
$rows = $this->dba->rawSelect($q);
The query looks like this now
SELECT item_id, name, price, details, img
FROM items
WHERE (details LIKE '%someword%' OR LIKE '%someword%')
OR (name LIKE '%someword%' OR LIKE '%someword%')
OR (description LIKE '%someword%' OR LIKE '%someword%')
I am not sure if I have to specify the column for every LIKE
or do something else
thanks, Richard
Upvotes: 0
Views: 186
Reputation: 10070
foreach(explode(" ", trim($words) ) as $word) $where[] = "LIKE '%$word%'";
$q = "SELECT item_id, name, price, details, img FROM items WHERE (details ".implode(" OR details ",$where).") OR (name ".implode(" OR names ",$where).") OR (description ".implode(" OR description ",$where).")";
$rows = $this->dba->rawSelect($q);
Upvotes: 1
Reputation: 172
I think you have to specify the column for every LIKE. BTW, why not just have a try running the sql? it will tell you everything.
Upvotes: 1