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

vikmalhotra picture vikmalhotra · Jul 22, 2010 · Viewed 41.6k times · Source

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

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

How can I implement this using Codeigniter active records?

Regards

Answer

Phil Sturgeon picture Phil Sturgeon · Jul 22, 2010
$this->db->set('usage', 'usage+1', FALSE);
$this->db->where('tag', 'java');
$this->db->update('tags');