我正试图让这个查询正确
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);
查询现在看起来像这样
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%')
我不确定是否必须为每个LIKE
指定列或执行其他操作
答案 0 :(得分:1)
我认为你必须为每个LIKE指定列。顺便说一句,为什么不尝试运行sql?它会告诉你一切。
答案 1 :(得分:1)
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);