Welcome Guest, Not a member yet? Register   Sign In
Update query with Active record
#1

[eluser]Ajaxian64[/eluser]
Hi all,

I use Active record for updating record but I can't go beyond on a very simple pattern.

I just would like to achieve for instance adding x to a record.

Something like this in MySql
Code:
Update 'mytable' SET xx = xx + $something WHERE cond1=$cond
But when I write
Code:
$this->db->where('cond1',$cond)->update('mytable',array('xx'=>"xx+$something")
Then I update nothing. When I use MySql statements I do the job

Do you know how to use this Active Record facilities to achieve my stuff?

Thanks
#2

[eluser]TaylorOtwell[/eluser]
Here is some code I've used before to do this...

Code:
$this->db->set('failed_sign_in_attempts', 'failed_sign_in_attempts + 1', FALSE);
$this->db->where('email', $value);
$this->db->update('users');

Instead of hard coding "+ 1", I think you could just concatenate in your value.
#3

[eluser]umefarooq[/eluser]
you have to use set function of Active Record try this will work

Code:
$this->db->set('xx',"xx+$somthing",FALSE);
$this->db->where('cond1',$cond);
$this->db->update('mytable');
#4

[eluser]Ajaxian64[/eluser]
Thank you all.




Theme © iAndrew 2016 - Forum software by © MyBB