
Update an existing table record with +1 in CodeIgniter
Created at 19-Mar-2021 ,
By samar
Update an existing table record with +1 in CodeIgniter
Through many examples, we will learn how to resolve the "Update an existing table record with +1 in CodeIgniter".
-
--PATH application\controllers\<yourcontroller>.php
$this->db->set('views', 'views + 1',FALSE); $this->db->where('id', $id); $this->db->update('posts');
You can update an existing table record with +1 in CodeIgniter using set() method. $this->db->set() method set value for column for insert or update query. $this->db->where() function enables you to set WHERE clause on query. set() method will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. which is used in our case and it generates a query like UPDATE posts SET views = views+1 WHERE id = 2. If the third parameter of set() method is not passed or passed as TRUE then it returns a query like UPDATE `posts` SET `views` = 'views+1' WHERE `id` = 2. You have to set FALSE to increment the value of the column of a record.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: CodeIgniter
- Call to undefined function CodeIgniter\locale_set_default()
- Get last executed query in codeigniter
- How to get field names of table in Codeigniter
- How to create custom helper in codeigniter 4
- Default htaccess file code Codeigniter
- How to load a view in CodeIgniter?
- Get the version codeIgniter
- How to select all checkbox in Codeigniter
- No input file specified Codeigniter
- Codeigniter 4 call model function from controller
- Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter
- How to call helper function in Codeigniter view
- Unable to set session in codeigniter
- How to move from one view to another in Codeigniter