We often need last inserted ID for different reasons(for example when you need to store foreign key), Immediately after a record has been inserted into the database, you can get the id that was auto incremented(primary Key).
Basic PHP MySQL Method
simply call CodeIgniter method
db->insert_id();?> ?>
That’s it!
Reference URL: http://codeigniter.com/user_guide/database/helpers.html