• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Record Class: How to increment a field by one using update?

This is the idea:

$this->db->update('files', array('hits' => 'hits+1'), array('id' => $id));

Is it possible?

I got it:

Checking "$this->db->set()"
in http://ellislab.com/codeigniter/user-gui...ecord.html
shows a suitable example with a field called "hits". So this is the way to do it:

$this->db->set('hits', 'hits+1', FALSE);
$this->db->where('id', $id);

Have you tried it? You will probably need to disable auto-escaping fields.

Yes, The third parameter in db->set(), prevents data from being escaped if set to FALSE.
Cool and easy framework. Ah?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.