Active Record Class: How to increment a field by one using update? |
[eluser]nomikos3[/eluser]
This is the idea: Code: $this->db->update('files', array('hits' => 'hits+1'), array('id' => $id)); Is it possible? Thanks,-
[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);
[eluser]danmontgomery[/eluser]
Have you tried it? You will probably need to disable auto-escaping fields.
[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.- |
Welcome Guest, Not a member yet? Register Sign In |