CodeIgniter Forums
Incrementing a column value in CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Incrementing a column value in CI (/thread-34805.html)



Incrementing a column value in CI - El Forum - 10-10-2010

[eluser]rupin[/eluser]
I have been trying to increment the count of a column in a table using the active record class.
Here is the code existing in my model

function increment_form_count($lorgID)
{
$this->db->set('createdForms', 'createdForms+1');
$this->db->where("orgID",$lorgID);
$this->db->update('organization');


}

When I lookup the MySQL logs the query that gets generated is

UPDATE `organization` SET `createdForms` = 'createdForms+1' WHERE `orgID` = '4'

The query looks OK, but the value in the DB has not incremented.

The type of column 'createdForms' is an INT type.

When I run the same query from phpmyadmin, the value gets updated.

Do i need to manually commit the transaction, since the value does not increment from code?


Incrementing a column value in CI - El Forum - 10-10-2010

[eluser]umefarooq[/eluser]
you have to set it false right now you columen value is going as string to make it integer you have to do this

Code:
$this->db->set('createdForms', 'createdForms+1',FALSE);

check user guide also

http://ellislab.com/codeigniter/user-guide/database/active_record.html


Incrementing a column value in CI - El Forum - 10-10-2010

[eluser]rupin[/eluser]
Thanks umefarooq...