2012-06-28 24 views
2

我想寫的是符合以下條件的學說查詢:如何編寫具有多個條件的原則查詢?

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

這是我有:

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

這是拉動正確款記錄,但是是拉動所有已發佈記錄記錄,而不是隻有那些設置爲1.

我覺得我需要隔離這兩個條件(這(或這個或這)),但我不知道如何。

回答

4

把你ORandWhere

$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(); 
相關問題