codeIgniter / PHP的活动记录将不会递增整数 [英] CodeIgniter/PHP Active Record won't increment an integer

查看:92
本文介绍了codeIgniter / PHP的活动记录将不会递增整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的查询,在codeIgniter的活动记录:

Here's my query, in CodeIgniter's Active Record:

function calculate_invites($userid)
{
    $this->db->where('id', $userid)
               ->update('users', array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
}

字段邀请 sentinvites 都是整数,但均设置为0,此功能运行后。这使我presume是codeIgniter正在通过邀请-1 sentinvites + 1 为字符串,但我想追加 FALSE 到最后停止了它这样做?

The fields invites and sentinvites are both integers but are set to 0 after the function is run. This makes me presume that CodeIgniter is passing invites-1 and sentinvites+1 as strings, but I thought appending FALSE to the end stopped it doing that?

谢谢!

杰克

推荐答案

这不符合更新,只有设置

这应该工作:

$this->db->where('id', $userid);
$this->db->set('invites', 'invites-1', FALSE);
$this->db->set('sentinvites', 'sentinvites+1', FALSE);
$this->db->update('users');

这可能工作太(用户指南有点不清):

This may work too (the user guide is a bit unclear):

$this->db->where('id', $userid);
$this->db->set(array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
$this->db->update('users');

这篇关于codeIgniter / PHP的活动记录将不会递增整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆