使用数据库字段值与cakephp中的savefield相加值(Add up value using database field value with savefield in cakephp)

编程入门 行业动态 更新时间:2024-10-18 20:29:21
使用数据库字段值与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` = 16

This is wrong and it should be:

UPDATE `advertisement` SET `total_views` = (total_views +1), `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16

The 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) );

更多推荐

本文发布于:2023-08-05 22:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1441003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   数据库   cakephp   savefield   database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!