2

I am trying to write a doctrine query that meets the following conditions:

published = 1
AND 
subsection = "gui" OR "lvo" OR "tnn" OR "wer"

This is what I have:

$getPrograms = Doctrine::getTable('Program')
  ->createQuery()
  ->where('published=?', '1')
  ->andWhere('subsection=?', 'gui')
  ->orWhere('subsection=?', 'lvo')
  ->orWhere('subsection=?', 'tnn')
  ->orWhere('subsection=?', 'wer')
  ->orderBy('title ASC')
  ->execute();

This is pulling the correct subsection records, but is pulling records all published records, instead of only ones set to 1.

I feel I need to isolate the two conditions ( this AND (this OR this OR this)) but I do not know how.

j0k
  • 22,600
  • 28
  • 79
  • 90
Carey Estes
  • 1,534
  • 2
  • 31
  • 59

1 Answers1

4

Put your OR in the andWhere :

$getPrograms = Doctrine::getTable('Program')
  ->createQuery()
  ->where('published=?', '1')
  ->andWhere(
    'subsection=? OR subsection=? OR subsection=? OR subsection=?', 
    array('gui', 'lvo', 'tnn', 'wer')
  )
  ->orderBy('title ASC')
  ->execute();
j0k
  • 22,600
  • 28
  • 79
  • 90