CodeIgniter Forums
Active Record Update Sum 1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Record Update Sum 1 (/showthread.php?tid=49607)



Active Record Update Sum 1 - El Forum - 02-26-2012

[eluser]Fantass[/eluser]
Im trying to each time that access to the method updade +1 like a counter.. This is what i got
Code:
$this->db->where('id',$row->id);
        $update = array(
            'counter' => +1,
        );
        $this->db->update('table', $update);
But instead sum 1 write '1' In te row.
Thanks


Active Record Update Sum 1 - El Forum - 02-26-2012

[eluser]InsiteFX[/eluser]
Code:
$this->db->set('field', 'field+1');



Active Record Update Sum 1 - El Forum - 02-27-2012

[eluser]Aken[/eluser]
Make sure to set the third parameter of the set() method to FALSE to keep active record from escaping your code. I don't think it'll work for most DBs without it. There's an example of this in the user guide for the set() method: http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert