db_or

7 database.inc db_or()
8 database.inc db_or()

Returns a new DatabaseCondition, set to "OR" all conditions together.

Return value

DatabaseCondition

Related topics

21 calls to db_or()

File

includes/database/database.inc, line 2630
Core systems for the database layer.

Code

function db_or() {
  return new DatabaseCondition('OR');
}

Comments

Example

Lifted from (http://drupal.org/node/310086). Pasting it here in case others hit this page first looking for the same.

<?php
// From taxonomy_term_save():
$or = db_or()->condition('tid1', 5)->condition('tid2', 6);
db_delete('term_relation')->condition($or)->execute();
// DELETE FROM {term_relation} WHERE ((tid1 = 5 OR tid2 = 6))
?>

db_or Loop

What would be the correct method to build a loop within this db_or() so that I can pull an amount of conditions from a previous database query? Here is what I have concocted so far but it doesn't seem to work:

$query->condition(db_or()
foreach ($subjids as $subjid) {
"->condition ('s.field_subject_tid', " . $subjid . ", '=')"
}
);

Try $db_or = db_or();

Try

$db_or = db_or();
foreach($subjids as $subjid){
     $db_or->condition('s.field_subject_tid',$subjid,'=');
}
$query->condition($db_or);

Thanks zerbash. That worked

Thanks zerbash. That worked really well for me.

Awesome, thank you!

Awesome, thank you!

Login or register to post comments