【问题标题】:Condition AND OR with Drupal db_select条件 AND OR 与 Drupal db_select
【发布时间】:2013-04-07 14:09:03
【问题描述】:

嗨,我怎样才能在 drupal 中做这样的条件?

WHERE (date = xxx and time = xxx) OR (date = xxx and time = xxx)

我想用 db_select 做这个条件。

谢谢。

【问题讨论】:

    标签: sql drupal-7 conditional-statements where


    【解决方案1】:

    像这样:

    $query = db_select('yourtable', 't');
    $query->condition(db_or()->condition(db_and()->condition('t.date', xxx, '=')->condition('t.time', xxx, '='))
                             ->condition(db_and()->condition('t.date', xxx, '=')->condition('t.time', xxx, '=')));
    

    【讨论】:

    • 这不对...产生SELECT FROM {yourtable} t WHERE (t.date = :db_condition_placeholder_0) AND (t.time = :db_condition_placeholder_1) AND( (t.date = :db_condition_placeholder_2) OR (t.time = :db_condition_placeholder_3) )
    【解决方案2】:

    感谢您的快速回答,我刚刚找到它。

    这是我的解决方案:

    $and_1 = db_and()->condition('b.date' , $date, '=')->condition('b.time', $begin_time, '>');
    $and_2 = db_and()->condition('b.date' , $tomorrow, '=')->condition('b.time', '00:00', '>=')
    
    $query->condition(db_or()->condition($and_1)->condition($and_2));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 2017-03-28
      相关资源
      最近更新 更多