高级MySQL搜索查询 - 使用RLIKE

时间:2014-03-14 11:53:30

标签: php mysql full-text-search rlike

1 个答案:

答案 0 :(得分:1)

你的查询中有这个奇怪的表达式:

WHERE product_name, customtitle RLIKE '".$searchstring."'

首先尝试使用concat()组合它们:

(SELECT p.virtuemart_product_id, l.product_name
 from #__virtuemart_products p join
      #__virtuemart_products_".VMLANG." l
      on p.virtuemart_product_id = l.virtuemart_product_id
 WHERE concat(product_name, customtitle) RLIKE '".$searchstring."' AND
       p.published = '1'
 LIMIT 0,".$prods."
)
union
(select p.virtuemart_product_id, l.product_name
 from #__virtuemart_products p join
      #__virtuemart_products_".VMLANG." l
      on p.virtuemart_product_id = l.virtuemart_product_id
 where product_sku RLIKE '".$searchstring."' and
       p.published = '1'
 LIMIT 0,".$prods.
)

你也可以单独比较每一个:

 WHERE (product_name RLIKE '".$searchstring."' OR
        customtitle RLIKE '".$searchstring."' 
       ) AND . . .

请注意,我还修复了join语法以使用显式连接。