2012-04-17 79 views
1

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

例子:

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 

这是正确的?因为我得到错误的结果。

+0

确保接受的答案。 – Aaron 2012-04-17 12:33:51

+0

是的。我会。谢谢 – Jetoox 2012-04-17 12:50:26

回答

6

试试这个

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

这实际上工作。谢啦。为什么我不认为连接音量和变量。再次感谢人。 :)当然可以 – Jetoox 2012-04-17 12:31:40

+0

。但stackoverflow说,我可以在一定的分钟后接受答案。但我会成为男人。谢谢 – Jetoox 2012-04-17 12:33:49

+0

@Jetoox ofc,当然 – safarov 2012-04-17 12:35:28