0

我正在尝试正确执行此查询

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或执行其他操作

谢谢,理查德

4

2 回答 2

1

我认为您必须为每个 LIKE 指定列。顺便说一句,为什么不尝试运行 sql 呢?它会告诉你一切。

于 2012-08-28T05:49:47.430 回答
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);
于 2012-08-28T06:56:35.943 回答