Rudra
Rudra

Reputation: 555

How to Insert Multiple row to multiple table at a once into database

There are three table as t1, t2 and t3. I'm trying to insert my row to multiple table using CodeIgniter as given above.

Code:

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name' ,
      'email' => 'E-mail'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name' ,
      'email' => 'E-mail'
   ),
   array(
      'title' => 'Another title 2' ,
      'name' => 'Another Name 2' ,
      'email' => 'E-mail 2'
   )
);

$i=1;
for($k=0;$k<3;$k++){
      $this->db->insert_batch('t'.$i++, $data); 
}

Upvotes: 0

Views: 70

Answers (1)

user8477089
user8477089

Reputation:

I hope , this stuff will work for you, just try this.

$data = array(
    array(
          'title' => 'My title' ,
          'name' => 'My Name' ,
          'email' => 'E-mail'
    ),
    array(
          'title' => 'Another title' ,
          'name' => 'Another Name' ,
          'email' => 'E-mail'
    ),
    array(
          'title' => 'Another title 2' ,
          'name' => 'Another Name 2' ,
          'email' => 'E-mail 2'
    )
);

$i=1;
for($k=0;$k<3;$k++)
{
   $this->db->insert_batch('t'.$i++, $data); 
}

Upvotes: 3

Related Questions