使用cakephp中的savefield将数据库字段值与值相加 [英] Add up value using database field value with savefield in cakephp
本文介绍了使用cakephp中的savefield将数据库字段值与值相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题很简单,但很难找到一个答案虽然搜索引擎。
my question is pretty simple but hard to find an answer for though search engines.
我只是想更新数据库中的字段,使用该字段旧值添加另一个值。我现在使用以下:
I simply want to update a field in the database, using that fields old value to add another value. I'm using the following at the moment:
$this->Advertisement->saveField('total_views', '(total_views + 1)', false);
但这给了我下一个查询:
But this gives me the next query:
UPDATE `advertisement` SET `total_views` = '(total_views +1)', `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16
这是错误的,应该是:
UPDATE `advertisement` SET `total_views` = (total_views +1), `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16
问题是它(total_views + 1)
在引号之间。
有没有人知道如何让这个工作?
Does anyone have an idea on how to get this working?
推荐答案
$this->Advertisement->updateAll(
array('Advertisement.total_views' => 'Advertisement.total_views + 1'),
array('Advertisement.id' => 1)
);
这篇关于使用cakephp中的savefield将数据库字段值与值相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文