Get last inserted id from database in Codeigniter use $this->db->insert_id();
If you want to get the last inserted id after insert success then follow this example:
<?php public function InsertData($data){ $ins_qry=$this->db->insert('table name',$data); if($ins_qry){ $last_id=$this->db->insert_id(); } } ?>
If you want to get another table value using the last inserted id then follow this example:
<?php public function InsertData($data){ $ins_qry=$this->db->insert('table name',$data); if($ins_qry){ $last_id=$this->db->insert_id(); $sec_qry = $this->db->select('*')->from('nest table name')->where('fk_some_id',$last_id)->get()->result(); } } ?>
See more Helpful Codeigniter Tutorial post. Visit fast.
Question and answer is powered by AnsPress.io