views:

206

answers:

2

In my form, there are values to be inserted to multiple tables. After inserting to the first table, i have to insert the other values, along with the 'id' of the entry to first table as reference. What is the best way to do this? Is there any codeigniter specific way?

+1  A: 

Try to use mysql_insert_id ();

Alexander.Plutov
+3  A: 

$this->db->insert_id() may be what you're looking for. Here's an example of how it could work:

$this->db->insert('Table1',$values);    
$table1_id=$this->db->insert_id();
$otherValues=array(
    'table1_id'=>$table1_id,
    );
$this->db->insert('otherTable',$otherValues);
stormdrain