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

时间:2017-08-23 10:47:05

标签: php mysql drupal drupal-7

我有2个类别' cele_birth'和' cele_anniv'。我想在drupal 7中的单个查询中获取这两个值。我尝试过如下。我只返回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);
}

2 个答案:

答案 0 :(得分:1)

您必须在sql中使用OR条件

var window: UIWindow?
var story : UIStoryboard?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.statusBarStyle = .lightContent
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    if let lunchedBefore = UserDefaults.standard.object(forKey: "lunchedBefore") {
        story = UIStoryboard(name: "TShopUI", bundle: nil)
        let rootcontroller = story?.instantiateViewController(withIdentifier: "LoginVC")
        if let window = self.window {
            window.rootViewController = rootcontroller
        }
    } else {
        UserDefaults.standard.set(true, forKey: "lunchedBefore")
        story = UIStoryboard(name: "TShopUI", bundle: nil)
        let rootcontroller = story?.instantiateViewController(withIdentifier: "MainVC")
        if let window = self.window {
            window.rootViewController = rootcontroller
        }
    }
    return true
}

答案 1 :(得分:0)

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