Retrieving the id of the latest inserted record is a common task. We need to use the id for other related tables.
CodeIgniter’s Query Builder class offers a simple method to get the latest id.
We only need to call $this->db->insert_id()
.
$this->db->set('username', 'tltemplates'); $this->db->set('password', 'hashedpass'); $this->db->set('firtsname', 'Green'); $inserted = $this->db->insert($this->table_quote); if($inserted){ $last_id = $this->db->insert_id(); }