我需要修改默认的 prestashop 数据库查询。我尝试了以下方法:
public function ajaxProcessCheckProductName()
{
if ($this->tabAccess['view'] === '1')
{
$search = Tools::getValue('q'); /* in this variable, i wish subsitute the space with % */
$searchmod = str_replace(" ", "%", $search);
$id_lang = Tools::getValue('id_lang');
$limit = Tools::getValue('limit');
$result = Db::getInstance()->executeS('
SELECT DISTINCT pl.`name`, p.`id_product`, pl.`id_shop`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
WHERE pl.`name` LIKE "%'.pSQL($searchmod).'%"
GROUP BY pl.`id_product`
LIMIT '.(int)$limit);
die(Tools::jsonEncode($result));
}
}
我希望kawasaki racing filter
用 % 替换变量中的空格,这样我就可以使用完整的通配符对 db 进行查询...
示例:用户搜索kawasaki racing filter
,我希望将其替换为kawasaki%racing%filter
so,查询将是%kawasaki%racing%filter%
...
该方法似乎正确吗?它现在不起作用:(
有人能帮我吗?提前致谢!