Update the value of a field in database by 1 using codeigniter

后端 未结 3 1298

I want to implement a SQL statement using codeigniter active record.

UPDATE tags SET usage = usage+1 WHERE tag=\"java\";

How can I implemen

相关标签:
3条回答
  • 2020-12-03 18:04

    You can also use something like this

    $data = array('usage' => 'usage+1', *other columns*);
    $this->db->where('tag', 'java');
    $this->db->update('tags', $data);
    

    UPDATE: $data was not being passed on to update

    0 讨论(0)
  • 2020-12-03 18:06

    I find its sometimes simpler to just write the SQL rather than having Active Record build it for me.

    $sql = 'update tags set usage=usage+1 where tag=?';
    $this->db->query($sql, array($tag));
    
    0 讨论(0)
  • 2020-12-03 18:14
    $this->db->set('usage', 'usage+1', FALSE);
    $this->db->where('tag', 'java');
    $this->db->update('tags');
    
    0 讨论(0)
提交回复
热议问题