更新字段会减去变量


Updating a field subtract from a variable

从变量值中减去字段值的正确语法是什么?

例:

field1 = 100
variable1 = 10

我想使用代码点火器的活动记录从字段 1 中减去变量 1

我当前的代码如下所示:

$this->db->set('volume', 'volume'-$r['quantity'], FALSE)
                    ->where('code',$r['ingredient_id'])
                    ->update('tbl_ingredients');
volume is the field
$r['quantity] is the variable

这是对的吗?因为我得到错误的结果。

试试这个

$this->db->set('volume', 'volume-'.$r['quantity'], FALSE)