Sql 在多列和多个类似';s

Sql 在多列和多个类似';s,sql,full-text-search,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 $wh

我正在努力把这个问题弄对

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%')
我不确定是否必须为每个
指定列,如
,或执行其他操作


谢谢,Richard

我想你必须为每一个喜欢的人指定一列。顺便说一句,为什么不试试运行sql呢?它会告诉你一切。

我只在第二行附近出现错误…不是很有用,我知道这是一个简单的问题,但它是有用的,我通常自己会想出一些困难的东西,后来发现可能会简单得多。谢谢,我做得有点不同,通过使用列名运行外部循环并将列名放入“wheresql”。@Richard我的SQL语句的优点是,您可以使用一个
$where
,并在任意多个列中使用它。。。
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);