Reputation: 360
Just want to increase the value in mysql table. Please see below the table. for example, my model should find the row with id 2, get the value of like column (5), increase it by one (5+1) and return the result (6). Could you please help me.
Here is my table:
Here is my model:
public function test($id){
$this->db->select('like');
$this->db->from('movies');
$this->db->where('id', $id);
$data = array (
'like' => " like + 1",
);
$this->db->update('movies', $data);
$query = $this->db->get();
if ($query->num_rows() == 1){
return $query->result();
}
else {
return false;
}
}
Upvotes: 0
Views: 109
Reputation: 7552
You don't need to use the select from
here.
Try something like this:
$this->db->where('id', $id);
$this->db->set('like', 'like+1', FALSE);
$this->db->update('movies');
$idU = $this->db->insert_id();
$r = $this->db->get_where('movies', array('id' => $idU));
return $r->row();
Upvotes: 2