title: insert multiple record to a table with codeigniter
body: <p>I want to insert the records (that i got from a table) to another table using codeigniter.
  here's the function to add the record. I pass the $nokw to insert to another table as foreign key.: </p>
  
  <pre><code>function add_detail($nokw){
      $id_sj = $this-&gt;session-&gt;userdata('id');
      $upddate = date('Y')."-".date('m')."-".date('d')." ".date('H').":".date('i').":".date('s');
      $i=0;
      $this-&gt;suratjalan-&gt;where('IDDeliveryNo',$id_sj);
      $rec = $this-&gt;suratjalan-&gt;get("t02deliveryno_d")-&gt;result_array();
  
      // parse the result and insert it into an array 
      foreach ($rec as $det){
      $i++;
          $detail[$i] = array(
              'ID' =&gt; '',
              'NoKwitansi' =&gt; $nokw,
              'TypeProduct'=&gt; $det['TypeProduct'],
              'PartNo' =&gt; $det['PartNo'],
              'PartNoVendor'=&gt; $det['PartNoVendor'],
              'SerialPanel' =&gt; $det['SerialPanel'],
              'Description' =&gt; $det['Description'],
              'Dimension'   =&gt; $det['Dimension'],
              'DescriptionVendor' =&gt; $det['DescriptionVendor'],
              'DimensionVendor' =&gt; $det['DimensionVendor'],
              'PrintedProduct' =&gt; $det['PrintedProduct'],
              'Qty' =&gt; $det['Qty'],
              'UoM' =&gt; $det['UoM'],
              'Remark' =&gt; $det['Remark'],
              'UpdUser'=&gt;  $this-&gt;session-&gt;userdata('user'),
              'UpdDate'=&gt; $upddate
          );
  
          // insert the record
          $this-&gt;finance-&gt;insert('t02fkpd',$detail[$i]);
      }
  }
  </code></pre>
  
  <p>It works, but it doesn't work if more than one row is returned from the table 't02deliveryno_d'. I think the error comes when i insert the record. i use the <code>$i++</code>to make different index in <code>$detail</code> array.</p>
  
  <p>How can I fix this to properly insert multiple rows?</p>