与Drupal db_select的条件和OR

时间:2013-04-15 12:49:04

标签: sql drupal-7 conditional-statements where

你怎么能在drupal中做这样的情况?

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

我想用db_select做这个条件。

感谢。

2 个答案:

答案 0 :(得分:8)

为了快速回答,我发现了它。

这是我的解决方案:

$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));

答案 1 :(得分: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, '=')));