1

how i can do that query:

UPDATE `xxx` SET `xx`=xx+1

with Active Record in Codeigniter ?

Thanks for your help ;-)

Jelean Thomas
  • 422
  • 1
  • 7
  • 19
  • possible duplicate of [Increment field of mysql database using codeigniter's active record syntax](http://stackoverflow.com/questions/6373564/increment-field-of-mysql-database-using-codeigniters-active-record-syntax) – Ben Fortune Aug 26 '14 at 11:46

3 Answers3

1

Try with the following code:

//$this->db->where('id', 'yourid');
$this->db->set('xx', 'xx+1',FALSE);
$this->db->update('xxx');
Jenz
  • 8,280
  • 7
  • 44
  • 77
1

Try this

$this->db->where('id',$id);
$this->db->update('xxx',array('xx',$xx+1));
rajangupta
  • 329
  • 2
  • 8
  • 15
0
$this->db->where('id', 'yourid');
$this->db->set('xx', '`xx`+1', FALSE);
$this->db->update('xxx');

Note the third parameter in the set function.

This function tells CodeIgniter not to add a backtick (`) on the field.

Pupil
  • 23,834
  • 6
  • 44
  • 66