在多列和多个LIKE上进行全文搜索的正确语法

时间:2012-08-28 05:43:37

标签: sql full-text-search

我正试图让这个查询正确

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

谢谢,理查德

2 个答案:

答案 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);