How to Update Database Field Value +1 in CodeIgniter

By Yashwant Chavan, Views 119, Last updated on 14-Apr-2019

In this tutorial, You will learn how to increment table field value using PHP Codeigniter. Recently I have implemented this in my blog when the article page viewed increment the view count by 1.

tags codeigniter

$this->db->set() This function enables you to set values for inserts or updates. set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE.

$this->db->where() Specify where condition. Like in this case I have specified movie id.

$this->db->update() Generates an update string and runs the query based on the data you supply.

function updateCount($movieId){
	$this->db->set('view', 'view+1', FALSE);        
    $where = array('movie_id' =>$movieId);



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]