使用数据库字段值与cakephp中的savefield相加值(Add up value using database field value with savefield in cakephp)
我的问题很简单,但很难找到搜索引擎的答案。
我只想更新数据库中的字段,使用旧字段值来添加另一个值。 我现在正在使用以下内容:
$this->Advertisement->saveField('total_views', '(total_views + 1)', false);但这给了我下一个查询:
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) 。
有没有人知道如何使这个工作?
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` = 16This is wrong and it should be:
UPDATE `advertisement` SET `total_views` = (total_views +1), `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16The problem is where it puts (total_views +1) between quotes.
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) ); $this->Advertisement->updateAll( array('Advertisement.total_views' => 'Advertisement.total_views + 1'), array('Advertisement.id' => 1) );更多推荐
发布评论