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

#1
[eluser]nomikos3[/eluser]
This is the idea:

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

Is it possible?
Thanks,-

#2
[eluser]nomikos3[/eluser]
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:

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

#3
[eluser]danmontgomery[/eluser]
Have you tried it? You will probably need to disable auto-escaping fields.

#4
[eluser]nomikos3[/eluser]
Yes, The third parameter in db->set(), prevents data from being escaped if set to FALSE.
Cool and easy framework. Ah?
Thanks.-


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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