phpcodeignitersql-updateadditionquery-builder

How to add an amount to a numeric column value using update() in CodeIgniter


I want to write a query like:

"Update table tbl_name set amount = amount + 100 where id = 10";

Is it possible to do such query builder methods?


Solution

  • This is the model function:

    function update($id) {
         $this->db->set('amount', 'amount+100', FALSE)
         $this->db->where('id ', $id);
         $this->db->update('tbl_name');
    }
    

    You can read the CI Active Record here