Welcome Guest, Not a member yet? Register   Sign In
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.-




Theme © iAndrew 2016 - Forum software by © MyBB