开发者

CodeIgniter/PHP Active Record won't increment an integer

开发者 https://www.devze.com 2023-01-15 02:10 出处:网络
Here\'s my query, in CodeIgniter\'s Active Record: function calculate_invites($userid) { $this->db->where(\'id\', $userid)

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

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 th开发者_如何转开发ought appending FALSE to the end stopped it doing that?

Thanks!

Jack


This doesn't work with update, only with set.

This should work:

$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');
0

精彩评论

暂无评论...
验证码 换一张
取 消