title: Inserting multiple rows mysql in codeigniter
body: <p>i am trying to insert multiple rows at once using Codeigniter</p>
  
  <p>my html code for codeigniter view</p>
  
  <pre><code>     &lt;?= form_open(base_url() . 'home/create') ?&gt;
              &lt;tbody&gt;
  
                  &lt;tr&gt;
                      &lt;td class="col-md-1 center-block"&gt;
                          &lt;input type="text" name="id[]" value="1" class="form-control" /&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="text" placeholder="enter descreption" class="form-control" name="desc[]" /&gt;
                      &lt;/td&gt;
                      &lt;td class="col-md-2 center-block"&gt;
                          &lt;input id="space"  onkeyup="sumPrice()" type="number" class="form-control" name="space[]" /&gt;
                      &lt;/td&gt;
                      &lt;td&gt; 
                          &lt;select onchange="sumPrice()" class="selectpicker price" data-live-search="true" data-width="100%" name="price[]" data-header="Select cost"&gt; 
                              &lt;option value="5"&gt;5&lt;/option&gt; 
                              &lt;option value="10"&gt;10&lt;/option&gt;
                              &lt;option value="20"&gt;20&lt;/option&gt;
                          &lt;/select&gt;
                      &lt;/td&gt; 
                      &lt;td class="total_price col-md-1"&gt;
                          &lt;input type="number" class="form-control" name="total[]" value="1000" /&gt;
                      &lt;/td&gt; 
                      &lt;td&gt;
                          &lt;button class="btn btn-danger center-block  remove-row"&gt;&lt;span class="glyphicon glyphicon-remove"&gt;&lt;/span&gt; Remove&lt;/button&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;input type="submit" value="insert" class="btn btn-success" /&gt;
      &lt;/form&gt;
      &lt;button class="btn btn-success append-row"&gt;&lt;span class="glyphicon glyphicon-plus-sign"&gt;&lt;/span&gt; Add new row&lt;/button&gt;
  </code></pre>
  
  <p>and i am using jQuery to insert new row in the table
  here is <code>js</code> the code</p>
  
  <pre><code>    $('.append-row').click(function() {
      $("table tbody").append
      ('&lt;tr&gt;&lt;td class="col-md-1 center-block"&gt;&lt;input type="text" name="id[]" value="' + row_id_val++ + '" class="form-control" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" placeholder="enter descreption" class="form-control" name="desc[]" /&gt;&lt;/td&gt; &lt;td class="col-md-2 center-block"&gt;&lt;input id="space"  onkeyup="sumPrice()" type="number" class="form-control" name="space[]" /&gt;&lt;/td&gt; &lt;td&gt; &lt;select onchange="sumPrice()" class="selectpicker price" data-live-search="true" data-width="100%" name="price[]" data-header="Select Sub account" onselect="sumPrice()" &gt; &lt;option onselect="sumPrice()" value="5"&gt;5&lt;/option&gt; &lt;option onselect="sumPrice()" value="10"&gt;10&lt;/option&gt; &lt;option onselect="sumPrice()" value="20"&gt;20&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td class="total_price col-md-1"&gt;&lt;input type="number" class="form-control" value=""  name="total[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;button class="btn btn-danger center-block  remove-row"&gt;&lt;span class="glyphicon glyphicon-remove"&gt;&lt;/span&gt; Remove&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;');
      $('.selectpicker').selectpicker('refresh');
  });
  </code></pre>
  
  <p>my controller</p>
  
  <pre><code>if ($_POST) {
      $data = array();
      for ($i = 0; $i &lt; count($this-&gt;input-&gt;post('id')); $i++) {
          $data[$i] = array(
              'row_id' =&gt; $this-&gt;input-&gt;post('id')[$i],
              'desc' =&gt; $this-&gt;input-&gt;post('desc')[$i],
              'space' =&gt; $this-&gt;input-&gt;post('space')[$i],
              'price' =&gt; $this-&gt;input-&gt;post('price')[$i],
              'total' =&gt; $this-&gt;input-&gt;post('total')[$i],
              'code' =&gt; time()
          );
      }
      $this-&gt;Home_model-&gt;create($data);
  }
  </code></pre>
  
  <p>model</p>
  
  <pre><code>function create($data) {
      $this-&gt;db-&gt;insert_batch('quotation', $data);
  }
  </code></pre>
  
  <p>i tried too many solutions from stackoverflow but none of them worked</p>