mysql - Subtract a value from a column in fuel php query builder -
i tried subtract numerical value 1 column in fuelphp query builder.
its this.
update item set cost = cost - 1000;
and wrote codes this:
$query = db::update('item')->set(array('price'=>'price'-1000));
however, doesn't subtract 1000 cost , result "price:-1000".
how should solve this?
alternatively, use/chain ->value()
in query builder , utilize db::expr()
on top of that.
example:
$value = 1000; $query = db::update('item') ->where('product_id', 999) ->value('price', db::expr('price - ' . $value)) // prefer using this, much more straightforward ->execute(); // dont forget execute!
or using ->set()
if decide utilize multiple fields:
->set(array( 'price' => db::expr('price - ' . $value) ))
php mysql fuelphp
No comments:
Post a Comment