Welcome Guest, Not a member yet? Register   Sign In
activer record_update
#1

[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?
#2

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

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

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

Cheers,
Smilie
#4

[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?
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB