Bhoj Raj Bhatta
Bhoj Raj Bhatta

Reputation: 2569

Updating field in Active Record

I want to write a query like

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

I found no documentation in CI Active Record library, Is it possible to do such query using acitve record?

Looking forward for your responses.

Upvotes: 0

Views: 41

Answers (2)

Erman Belegu
Erman Belegu

Reputation: 4079

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

Upvotes: 3

bipen
bipen

Reputation: 36531

you can do that by using $this->db->set();

try this

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

Upvotes: 0

Related Questions