gpt4 book ai didi

cakephp - 按值递增 Cakephp 数据库字段

转载 作者:行者123 更新时间:2023-11-30 23:28:37 25 4
gpt4 key购买 nike

我有这个字段,我必须将字段值增加一个特定值。我正在使用这个

$data['quantity']     = 'Order.quantity+1';

对我不起作用的数量是这里的整数列。当数据库中没有任何内容时它也能工作吗?

问候希曼舒沙玛

最佳答案

我在我的代码中使用了 updateAll 来增加一篇文章的浏览量。因此,每次访问一篇文章时,我都会在文章 Controller 的 View 操作中调用以下函数:

function incrementViewCount($id) {
$this->updateAll(
array('Article.viewed' => 'Article.viewed+1'),
array('Article.id' => $id)
);
}

然后在你的 Controller 中......

$this->MyModel->incrementViewCount(123);

基本类似于上一个答案中建议的教程。

关于cakephp - 按值递增 Cakephp 数据库字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11818785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com