update views+1 doesn't work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: update views+1 doesn't work (/showthread.php?tid=78489) |
update views+1 doesn't work - alakian - 01-28-2021 I need to update counter views: In Controller: PHP Code: public function show(string $slug) In Modal: PHP Code: class PostModel extends Model In action views table didn't update and show always 0. How do can I fix this problem? RE: update views+1 doesn't work - iRedds - 01-28-2021 Set the third parameter in the set() method to false. https://codeigniter.com/user_guide/database/query_builder.html#updating-data ps: Don't use QueryBuilder in the controller. This is bad practice. RE: update views+1 doesn't work - alakian - 01-28-2021 if I add FALSE I see this error: Code: mysqli_sql_exception #1064 you right! my code just for try. Quote:ps: Don't use QueryBuilder in the controller. This is bad practice. RE: update views+1 doesn't work - nicojmb - 01-28-2021 Hi, try using "increment" method: PHP Code: $this->postModel->where('id', $post->id)->increment('views'); https://codeigniter.com/user_guide/database/query_builder.html?highlight=increment#increment RE: update views+1 doesn't work - alakian - 01-30-2021 (01-28-2021, 06:50 AM)nicojmb Wrote: Hi, try using "increment" method: Hello! thanks working now. |