Reputation: 1564
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.
Upvotes: 2
Views: 2321
Reputation: 22756
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();
Upvotes: 4