我有以下sql:
tbl_items
title extra_fields
Prod1 [{"id":"2","value":"1"},{"id":"3","value":"1"},{"id":"4","value":"2"}]
Prod2 [{"id":"2","value":"1"},{"id":"3","value":"2"},{"id":"4","value":"1"}]
Prod3 [{"id":"2","value":"2"},{"id":"3","value":"2"},{"id":"4","value":"1"}]
Prod4 [{"id":"2","value":"2"},{"id":"3","value":"1"},{"id":"4","value":"1"}]
Prod5 [{"id":"2","value":"2"},{"id":"3","value":"1"}]
Prod6 [{"id":"2","value":"1"},{"id":"3","value":"1"}]
Prod7 [{"id":"2","value":"1"},{"id":"3","value":"1"},{"id":"4","value":"1"}]
Prod8 [{"id":"2","value":"1"},{"id":"3","value":"1"}]
现在,我想选择包含值{"id":"2","value":"2"};
的所有产品
我正在使用joomla cms
..
我尝试了以下声明:
$db->setQuery('SELECT * FROM tbl_items WHERE extra_fields LIKE "%{"id":"2","value":"2"}%"');
$xFields = $db->loadObjectList();
但它对我不起作用,任何人都可以帮忙吗?
答案 0 :(得分:0)
您的搜索字符串是双引号:
"%{"id":"2","value":"2"}%"
我不知道你怎么逃避它,但它需要导致:
'%{"id":"2","value":"2"}%'
以下内容可能有效:
$query = "
SELECT *
FROM ".$db->nameQuote('tbl_items')."
WHERE ".$db->nameQuote('extra_fields')." LIKE ".$db->quote('%{"id":"2","value":"2"}%').";
";
$db->setQuery($query);