use arithmetic find conditions cakephp

Discussion in 'PHP' started by glagokulan, Jan 3, 2013.

  1. #1
    Hi,

    How to use arithmetic conditions in cakephp find.

    For Ex: select * from table where a_column+b_column>500

    If any one know the way,Please reply..
     
    glagokulan, Jan 3, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    If a_column and b_column are numeric columns, that should work. If they're not, you'll have to use CAST to convert each of them to a numeric value first. ('one' + 'two' isn't 'three', it's 'onetwo'.) So "SELECT * FROM table WHERE (CAST(a_column AS DECIMAL) + CAST(b_column AS DECIMAL)) > 500;"

    That's all assuming that your database is MySQL. For other databases the syntax may be different.
     
    Rukbat, Jan 4, 2013 IP
  3. zhaff

    zhaff Active Member

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #3
    Hi,

    You can use conditions like this:

    $test = $this->Invoice->find('all', array('conditions' =>
    array('(Invoice.total_price + Invoice.shipping_rate) >' => 100)
    ));

    Hope its help.
     
    zhaff, Jan 6, 2013 IP