How to get value from last inserted row using Codeigniter
6 answers
try this code:
$this->db->insert_id();
See: http://ellislab.com/codeigniter/user_guide/database/helpers.html
+9
source to share
I have some tips for you. When you want to insert data, return the dataset and you can edit it.
public function set_alb_photos() {
$data = array(
'alp_title' => $this->input->post('alp_title'),
'alp_file_location' => $this->input->post('alp_file_location'),
'alp_album_id' => $this->input->get('alb_id'),
'alp_created_at' => date("Y-m-d H:i:s"),
'alp_updated_at' => date("Y-m-d H:i:s")
);
$this->db->insert('alb_photos', $data);
return $data;
}
I hope this help.
+2
source to share