更新字段从变量中减去

Jet*_*oox 1 php mysql records codeigniter

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

例:

field1 = 100
variable1 = 10
Run Code Online (Sandbox Code Playgroud)

我想使用codeigniter的活动记录从field1中减去variable1

我目前的代码如下:

$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
Run Code Online (Sandbox Code Playgroud)

它是否正确?因为我得到了错误的结果.

saf*_*rov 5

试试这个

$this->db->set('volume', 'volume-'.$r['quantity'], FALSE)
Run Code Online (Sandbox Code Playgroud)