Views in post - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Views in post (/showthread.php?tid=68646) |
Views in post - Marcolino92 - 08-07-2017 Hi guys, I'm looking at Codeigniter these days and I'll need your help. I have this class that is nothing but the display of every single page, but I needed to enter a query, where every access was updated to the field "views" in the database. PHP Code: public function get_post($slug = FALSE) { I've added a query that add +1 to the view field, but obviously does not count. So I need to +1 the current value of the field views. PHP Code: public function get_post($slug = FALSE) { Thanks! RE: Views in post - jarmen_kell - 08-07-2017 you can always do this, to set your value by increment-1 PHP Code: $this->db->set('views', 'views+1', FALSE)->where('slug'=>$slug); and this is already documented inside CI's documentation, if you would like to explore the docs more thoroughly: https://www.codeigniter.com/user_guide/database/query_builder.html#updating-data RE: Views in post - Marcolino92 - 08-08-2017 Perfect thank you very much. I solved this syntax: PHP Code: $this->db->set('field', 'field+1', FALSE); Thanks! |