CodeIgniter Forums
activer record_update - 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: activer record_update (/showthread.php?tid=50254)



activer record_update - El Forum - 03-20-2012

[eluser]Josssi[/eluser]
hi people,
i am sloving ona problem with update one field in my DB. I need to increase 'stack' in table 'customers' for actually $id adding $sum to currently value in 'stack'. In active record manual i didnt find correct reason, so i tried to write something like below:

function updateStack($id, $sum)
{
$this->db->where('id', $id)
->set('stack', 'stack+'.$sum)
->update('customers');
}

Something gets wrong and i dont know where should be a problem. Can somebody give me an advice how to do it correctly please?


activer record_update - El Forum - 03-20-2012

[eluser]Josssi[/eluser]
i just want to say, that in this state, this functuion in the field 'stack' add 0.


activer record_update - El Forum - 03-20-2012

[eluser]smilie[/eluser]
Haven't tested, but try:

->set('stack = stack + '.$sum,'',FALSE)

Cheers,
Smilie


activer record_update - El Forum - 03-20-2012

[eluser]Josssi[/eluser]
thank you very much for reaction...finally somebody Big Grin...it tried to write it like in your version, but it gives me this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id` = '8'' at line 1

UPDATE `customers` SET `stack` = stack +3 = WHERE `id` = '8'

Filename: E:\wamp\www\diplomka\system\database\DB_driver.php

Could hou helm me whad did I do bad plese?


activer record_update - El Forum - 03-20-2012

[eluser]Josssi[/eluser]
well, now is all ok, i tried again my version, but now with last param FALSE. Now it goes. I didnt understand meaning of this param before Wink