codeIgniter / PHP的活动记录将不会递增整数整数、codeIgniter、PHP

2023-09-09 22:12:42 作者:你给我听好

下面是我的查询,在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');