phpmysqlcodeignitersql-updateincrement

How to increment a column value using CodeIgniter's update()


I have another problem again on querying in CodeIgniter, I'll try to insert and update a "comment" on my website, but it's not working yet.

Here's my code :

on the Models (news_model.php)

public function simpan_komentar()
{
    $data1 = array(
        'komentar' => 'komentar + 1',
    );
    $this->db->update('news', $data1);
}

The update query didn't work. Where's my fault?


Solution

  • Try this

    $this->db->set('komentar', 'komentar+1', FALSE);
    //add your where condition if any
    $this->db->update('news');