title: How to loop insert data to database in codeigniter?
body: <p>I want insert data using loop to my database. I have view, name is <strong>'form.php'</strong>.</p>
  
  <pre><code>&lt;!-- STEP 3 --&gt;
  &lt;fieldset&gt;
      &lt;h2&gt;Kebutuhan Khusus&lt;/h2&gt;&lt;p&gt;(bila ada)&lt;/p&gt;
  &lt;div class="form-group"&gt;
  &lt;label&gt;Calon Mahasiswa&lt;/label&gt;
    &lt;select name="keb[0][jns_kebutuhan]" class="form-control" id="cama"&gt;
      &lt;option value=""&gt;--Jenis Kebutuhan--&lt;/option&gt;
      &lt;option value="Tuna Netra"&gt;Tuna Netra&lt;/option&gt;
      &lt;option value="Tuna Grahita"&gt;Tuna Grahita&lt;/option&gt;
      &lt;option value="Tuna Wicara"&gt;Tuna Wicara&lt;/option&gt;
      &lt;option value="Tuna Rungu"&gt;Tuna Rungu&lt;/option&gt;
      &lt;option value="Tuna Daksa"&gt;Tuna Daksa&lt;/option&gt;
      &lt;option value="Lainnya"&gt;Lainnya&lt;/option&gt;
    &lt;/select&gt;
    &lt;input type="hidden" class="form-control" name="keb[0][subjek]" value="Calon Mahasiswa"&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
  &lt;label&gt;Ayah&lt;/label&gt;
    &lt;select name="keb[1][jns_kebutuhan]" class="form-control" id="ayah"&gt;
      &lt;option value=""&gt;--Jenis Kebutuhan--&lt;/option&gt;
      &lt;option value="Tuna Netra"&gt;Tuna Netra&lt;/option&gt;
      &lt;option value="Tuna Grahita"&gt;Tuna Grahita&lt;/option&gt;
      &lt;option value="Tuna Wicara"&gt;Tuna Wicara&lt;/option&gt;
      &lt;option value="Tuna Rungu"&gt;Tuna Rungu&lt;/option&gt;
      &lt;option value="Tuna Daksa"&gt;Tuna Daksa&lt;/option&gt;
      &lt;option value="Lainnya"&gt;Lainnya&lt;/option&gt;
    &lt;/select&gt;
    &lt;input type="hidden" class="form-control" name="keb[1][subjek]" value="Ayah"&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
  &lt;label&gt;Ibu&lt;/label&gt;
    &lt;select name="keb[2][jns_kebutuhan]" class="form-control" id="ibu"&gt;
      &lt;option value=""&gt;--Jenis Kebutuhan--&lt;/option&gt;
      &lt;option value="Tuna Netra"&gt;Tuna Netra&lt;/option&gt;
      &lt;option value="Tuna Grahita"&gt;Tuna Grahita&lt;/option&gt;
      &lt;option value="Tuna Wicara"&gt;Tuna Wicara&lt;/option&gt;
      &lt;option value="Tuna Rungu"&gt;Tuna Rungu&lt;/option&gt;
      &lt;option value="Tuna Daksa"&gt;Tuna Daksa&lt;/option&gt;
      &lt;option value="Lainnya"&gt;Lainnya&lt;/option&gt;
    &lt;/select&gt;
    &lt;input type="hidden" class="form-control" name="keb[2][subjek]" value="Ibu"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And my controller '<strong>Pascasarjana.php</strong>'</p>
  
  <pre><code>foreach ($_POST['keb'] as $keb) {
      $this-&gt;m_pascasarjana-&gt;kebutuhan('tbl_kebutuhan',$keb);
    }
  </code></pre>
  
  <p>And my model is</p>
  
  <pre><code>function kebutuhan($table,$data) {
    $last_row = $this-&gt;db-&gt;select('id_pendaftar')-&gt;order_by('id_pendaftar',"desc")-&gt;limit(1)-&gt;get('tbl_datapribadi')-&gt;row()-&gt;id_pendaftar;
    $data['id_pendaftar'] = $last_row;
    $query = $this-&gt;db-&gt;insert($table,$data);
    return $this-&gt;db-&gt;insert_id();
  } //END FUNCTION//
  </code></pre>
  
  <p>I try using my controller, If one of the forms is not filled data contains 0 in my database. I want if i not filled one of the forms, no data filled in the database. How to make it?</p>