Reputation: 39
i'm new to Codeigniter, but learning from web, actually i got stuck with a unknown proble.
im inserting data into the database throw the model, and fetching back the data into form.
but when i'm updating the form i want to return the updated id.
i used $user_id = $this->db->insert_id();
but this is for getting insert id,
even i tried this
$this->db->where('id_colum', $student_id);
$this->db->update('table_name', $data);
$user_id = $this->db->insert_id();
return $user_id;
help me out, Thanks for everything..
Upvotes: 2
Views: 13158
Reputation: 442
$this->db->where('id_colum', $student_id);
$updatedId = $this->db->get('table_name')->row()->id;
$this->db->where('id', $updatedId);
$this->db->update('table_name', $data);
if($this->db->affected_rows() > 0){
return $updatedId;
} else {
return false;
}
Upvotes: 0
Reputation: 4097
Just do like this:
$this->db->where('id_colum', $student_id);
$this->db->update('table_name', $data);
$updated_status = $this->db->affected_rows();
if($updated_status):
return $student_id;
else:
return false;
endif;
If it is updated, then return back that $student_id. :)
Upvotes: 11