在单个数组中获取两个类别值

fetch two category value in single array

我有 2 个类别 'cele_birth' 和 'cele_anniv'。我想在 drupal 7.I 中的单个查询中获取这两个值 below.I returns仅 cele_anniv result.how 获取两个

$result = db_query('select response from {soap_service} where category = :category',array(':category' => 'cele_birth',':category' => 'cele_anniv'));
foreach($result as $record){
 $data = $record->response;
 $data = drupal_json_decode($data);
 print_r($data);
}

您必须在 sql

中使用 OR 条件
$result = db_query('select response from {soap_service} where category = :category1 OR category = :category2',array(':category1' => 'cele_birth',':category2' => 'cele_anniv'));

Siddharth 的回答是正确的,但当我们有很多值要比较时不适合。还有另一种解决方法,它将减少使用 IN 运算符多次写入 OR 条件。

$result = db_query('select response from {soap_service} where category in (:category)',array(':category' => array('cele_birth', 'cele_anniv')));

可以在此处找到有关 IN 运算符的更多详细信息SQL in operator