introducing: insert_id()
like this
$id = $this->db->insert_id();
return $id;
in your model, lets call it friend_model
function insertRow()
{
// Prepare data, normally you would pass this in
$data = array(
'first' => 'john',
'last' => 'smith'
);
// insert data
$this->db->insert( 'friends', $data );
// confirm insert
if ( $this->db->affected_rows() == '1' )
// return new ID
{ $id = $this->db->insert_id();
return $id; }
// else did not insert, return false
else {return FALSE;}
}
in your controller, check if you got an id back from model
if(! $id = $this->friend_model->insertRow() )
// it no work
{ // some error method
}
else
{ // success !
}