How to create Codeigniter batch insert array

This is your data At Controller

$dataForDb[0]['track_id']=$data['track_id'];
$dataForDb[0]['camp_id']=$data['camp_id'];
$dataForDb[0]['field_name']=$data['field_name'];
$dataForDb[0]['field_value']=$data['field_value'];

$dataForDb[1]['track_id']=$data['track_id'];
$dataForDb[1]['camp_id']=$data['camp_id'];
$dataForDb[1]['field_name']=$data['field_name'];
$dataForDb[1]['field_value']=$data['field_value'];

$dataForDb[2]['track_id']=$data['track_id'];
$dataForDb[2]['camp_id']=$data['camp_id'];
$dataForDb[2]['field_name']=$data['field_name'];
$dataForDb[2]['field_value']=$data['field_value'];

$fid=$this->model_modelName->functionName($dataForDb);

And insert data as batch insert At Model

$this->db->insert_batch($table, $data);

Try this:

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name' ,
      'date' => 'My date'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name' ,
      'date' => 'Another date'
   )
);

$this->db->insert_batch('mytable', $data); 

For more information, read here


Your array is ok. Just put your array into a variable like

$data=array();//put your array

and then

 $this->db->insert_batch('yourTable', $data);

Please let me know if you face any problem.