CodeIgniter Forums
How to increment an integer in MySQL? - 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: How to increment an integer in MySQL? (/showthread.php?tid=47659)



How to increment an integer in MySQL? - El Forum - 12-16-2011

[eluser]machouinard[/eluser]
I'm trying to increment a 'count' field in a MySQL table.

Table is InnoDB.
Count field is int(11).

When I run this, it sets the count to whatever $count is instead of incrementing it.

What am I missing here?
Do I need to get the value of count first, add that to $count, then update?
Seems like this should work.
Code:
public function increase_count($album_id=2, $count=1){
        $data = array(
         'count' => 'count' + $count,
        );
        $this->db->where('id', $album_id);
        if($this->db->update('album', $data)){
            echo 'Count should be updated';
        }
        die();
        
    }


Thanks,
Mark

EDIT: Changed title from increase to increment.