在drupal查询中,我希望获得两个类别'生日和周年纪念日'使用query.I想要获取数组中的值。对于单个类别,我已将值收集为
$result = db_query('select response from {soap_service} where category = :category',array(':category' => 'anniversary'));
but for both (which I have tried)
$result = db_query('select response from {soap_service} where category = :category',array(':category' => 'anniversary',':category' => 'birthday'));
真的要检查一下 category =' cele_birth'或类别=' cele_anniv'";
答案 0 :(得分:3)
你可以这样做,
$arr = ['anniversary','birthday'];
$result = db_query('select response from {soap_service} where category IN (:category)',array(':category' => $arr ));
正如核心编码标准所示,同一数组中的键不能相同,它会用新值覆盖它的值(键值更高的索引值)。
答案 1 :(得分:1)
基本上IN条件类似于多个OR条件,但您不必重写列名。此外,它可能在某些条件下比OR语句执行得更快。
这应该有效:
db_query('select response from {soap_service} where category IN (:category)',
array(':category' => array('anniversary', 'birthday'))->fetchAll();
答案 2 :(得分:0)
试试这个:
$categories = array(anniversary,birthday);
$result = db_query('select response from {soap_service} where category IN (:categories )', array(':categories ' => $categories ));
有关详细信息,请see,尤其是关于占位符数组的章节:
占位符数组