Search code examples
zend-framework

Zend Framwork OR operator use


I am using

$where->equalTo('dailyshifthr.thrs', 0);
$where->equalTo('dailyshifthr.thrsA', 0);

I need these two condition in OR not AND condition. Help me.


Solution

  • You should use the or predicate, like:

    $where->or->equalTo('dailyshifthr.thrs', 0);
    $where->or->equalTo('dailyshifthr.thrsA', 0);
    

    If you want to nest these two conditions with others, like

    SELECT *
    from your_table
    where field_a = 1
    and (dailyshifthr.thrs = 0 or dailyshifthr.thrsA = 0)
    

    Then you must use the nest predicate:

    $where->equalTo('field_a', 1);
    $nest = $where->nest;
    $nest->or->equalTo('dailyshifthr.thrs', 0);
    $nest->or->equalTo('dailyshifthr.thrsA', 0);