Skip to main content
reformat indentation for legibility
Source Link
greggles
  • 5.3k
  • 21
  • 37

with help of question pointed by @molot I could make it work, here is the code

$query = db_select('mytable');
$db_or = db_or();
$db_or->condition(
      db_and()
    db_and()->condition("condition1","value1")
                 ->condition(
                     db_or()
        db_or()->condition("condition2","value2")->condition("condition3","value3")
                             ->condition("condition3","value3")
));
$db_or->condition(
      db_and()
    db_and()->condition("condition4","value4")
                 ->condition(
                     db_or()
        db_or()->condition("condition5","value5")->condition("condition6","value6")
                             ->condition("condition6","value6")
));
$query->condition($db_or);

  $src = $query->__toString();
dpm($src);

and here is the output

SELECT 
FROM 
{mytable} mytable
WHERE (( (condition1 = :db_condition_placeholder_0) AND( (condition2 = :db_condition_placeholder_1) OR (condition3 = :db_condition_placeholder_2) ))OR( (condition4 = :db_condition_placeholder_3) AND( (condition5 = :db_condition_placeholder_4) OR (condition6 = :db_condition_placeholder_5) )))

with help of question pointed by @molot I could make it work, here is the code

$query = db_select('mytable');
$db_or = db_or();
$db_or->condition(
          db_and()->condition("condition1","value1")
                 ->condition(
                             db_or()->condition("condition2","value2")->condition("condition3","value3")
                             ));
$db_or->condition(
          db_and()->condition("condition4","value4")
                 ->condition(
                             db_or()->condition("condition5","value5")->condition("condition6","value6")
                             ));
$query->condition($db_or);

  $src = $query->__toString();
dpm($src);

and here is the output

SELECT 
FROM 
{mytable} mytable
WHERE (( (condition1 = :db_condition_placeholder_0) AND( (condition2 = :db_condition_placeholder_1) OR (condition3 = :db_condition_placeholder_2) ))OR( (condition4 = :db_condition_placeholder_3) AND( (condition5 = :db_condition_placeholder_4) OR (condition6 = :db_condition_placeholder_5) )))

with help of question pointed by @molot I could make it work, here is the code

$query = db_select('mytable');
$db_or = db_or();
$db_or->condition(
  db_and()
    ->condition("condition1","value1")
    ->condition(
      db_or()
        ->condition("condition2","value2")
        ->condition("condition3","value3")
));
$db_or->condition(
  db_and()
    ->condition("condition4","value4")
    ->condition(
      db_or()
        ->condition("condition5","value5")
        ->condition("condition6","value6")
));
$query->condition($db_or);

$src = $query->__toString();
dpm($src);

and here is the output

SELECT 
FROM 
{mytable} mytable
WHERE (( (condition1 = :db_condition_placeholder_0) AND( (condition2 = :db_condition_placeholder_1) OR (condition3 = :db_condition_placeholder_2) ))OR( (condition4 = :db_condition_placeholder_3) AND( (condition5 = :db_condition_placeholder_4) OR (condition6 = :db_condition_placeholder_5) )))
Source Link
arpitr
  • 7.9k
  • 2
  • 23
  • 48

with help of question pointed by @molot I could make it work, here is the code

$query = db_select('mytable');
$db_or = db_or();
$db_or->condition(
          db_and()->condition("condition1","value1")
                 ->condition(
                             db_or()->condition("condition2","value2")->condition("condition3","value3")
                             ));
$db_or->condition(
          db_and()->condition("condition4","value4")
                 ->condition(
                             db_or()->condition("condition5","value5")->condition("condition6","value6")
                             ));
$query->condition($db_or);

  $src = $query->__toString();
dpm($src);

and here is the output

SELECT 
FROM 
{mytable} mytable
WHERE (( (condition1 = :db_condition_placeholder_0) AND( (condition2 = :db_condition_placeholder_1) OR (condition3 = :db_condition_placeholder_2) ))OR( (condition4 = :db_condition_placeholder_3) AND( (condition5 = :db_condition_placeholder_4) OR (condition6 = :db_condition_placeholder_5) )))