Welcome Guest, Not a member yet? Register   Sign In
How to increment an integer in MySQL?
#1

[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.




Theme © iAndrew 2016 - Forum software by © MyBB