CodeIgniter/PHP Active Record won't increment an integer

后端 未结 1 1268
南笙
南笙 2021-01-02 15:07

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

function calculate_invites($userid)
{
    $this->db->where(\'id\', $userid)
               ->upda         


        
相关标签:
1条回答
  • 2021-01-02 15:26

    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 讨论(0)
提交回复
热议问题