How to UPDATE DB values using active record? |
[eluser]pernavoi[/eluser]
What is active record syntax for following query? amount1 and amount2 are INT values and I want to add values to them from data array Code: $this->db->query("UPDATE mytable
[eluser]techgnome[/eluser]
It's all in the User Guide... all you have to do is click and read - http://ellislab.com/codeigniter/user-gui...tml#update -tg
[eluser]pernavoi[/eluser]
I was just blind, didn't notice that how to use SET for adding values on first couple of reads. So it's this simple: Code: $this->db->set('amount1', 'amount1' + $data['amount1'] );
[eluser]pernavoi[/eluser]
But it still doesn't work...... Code: $this->db->set('field', 'field' + $data['field'] ); This gives: UPDATE `table` SET `field` = 1 WHERE `id` = '2' While it should be: UPDATE `table` SET field = field + '1' WHERE `id` = '2' EDIT - Finally solved: Pretty basic PHP :red: Code: $this->db->set('field', 'field + '.$data['field'].'', FALSE); |
Welcome Guest, Not a member yet? Register Sign In |