title: codeigniter array and loop to insert for multiple data
body: <p>I want to make an invoice form. For this reason i need to insert multiple data at once. for example I want to input db 5 category sale or purchase product at a time. But I am not interested with <strong>insert_batch</strong>. I try but i got some null value in db. </p>
  
  <p>My Model is:</p>
  
  <pre><code> &lt;?php
   class Purchase_model extends CI_Model{
  
    public function purchase(){
  
  
    $price = $this-&gt;input-&gt;post('price');
    $quantity = $this-&gt;input-&gt;post('quantity');
    $date = $this-&gt;input-&gt;post('date');
       $vendor_name = $this-&gt;input-&gt;post('vendor_name');
       $model = $this-&gt;input-&gt;post('model');
  
      $invoice_no = $this-&gt;input-&gt;post('invoice');
      //$temp = count($this-&gt;input-&gt;post('vendor_name'));
    for($i=0; $i&lt;10; $i++){  
      $data = array(
       'date'=&gt;$date[$i], 
       'vendor_name'=&gt;$vendor_name[$i],
       'model'=&gt;$model[$i],
       'price' =&gt;$price[$i], 
       'purchase_quantity'=&gt;$quantity[$i],
       'amount'  =&gt;$price[$i]*$quantity[$i],
       'invoice_no'=&gt;$invoice_no[$i]
       );
  
        $insert = $this-&gt;db-&gt;insert('purchase',$data);
       return $insert; }
        }}
  </code></pre>
  
  <p>My controller is:</p>
  
  <pre><code>public function purchase(){
  
      if($this-&gt;Purchase_model-&gt;purchase()){
  
          $this-&gt;session-&gt;set_flashdata('Success', 
              'You are entered data successfully');
          redirect('home/purchase_form');
      }
  }
  </code></pre>
  
  <p>My view for example:</p>
  
  <pre><code>  &lt;?php echo form_label ('Price:'); ?&gt;   
        &lt;select name="price[]" id="price" class="input-xlarge"&gt;
  
        &lt;/select&gt;
  
  
  
        &lt;?php echo form_label ('Quantity'); ?&gt; 
  
        &lt;?php 
              $data = array ('name'      =&gt;'quantity[]',
             'class'     =&gt;'input-xlarge',
             'value'     =&gt; set_value('quantity')); ?&gt;
  
        &lt;?php echo form_input ($data); ?&gt;
  
        &lt;?php echo form_label ('Price:'); ?&gt;   
             &lt;select name="price[]" id="price2" class="input-xlarge"&gt;
  
             &lt;/select&gt;
  
        &lt;?php echo form_label ('Quantity'); ?&gt; 
  
        &lt;?php 
             $data = array ('name'      =&gt;'quantity[]',
             'class'     =&gt;'input-xlarge',
             'value'     =&gt; set_value('quantity')); ?&gt;
  
        &lt;?php echo form_input ($data); ?&gt;
  </code></pre>
  
  <p>Please help.</p>