title: Insert multiple data in dynamically added table to database with codeigniter
body: <p>I have a table with dynamically added rows. Something like this</p>
  <p><a href="https://i.stack.imgur.com/EvzuJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EvzuJ.jpg" alt="enter image description here" /></a></p>
  <p>User can add rows in each category (Basic, Type Rating, and General) dynamically. And when they click on &quot;Save Record&quot; button, the data will be stored in database.</p>
  <p>I will share the code for one category (BASIC) only to represent the other categories.</p>
  <p>This is how the table ('t_basic') in database looks like</p>
  <p><a href="https://i.stack.imgur.com/iQX0y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iQX0y.jpg" alt="enter image description here" /></a></p>
  <p><strong>VIEW (body.php)</strong> (only the first category (Basic))</p>
  <pre><code>&lt;table id=&quot;myTable0&quot; name=&quot;myTable0&quot; class=&quot;table table-bordered&quot; style=&quot;width:100%; margin-bottom: 10px;&quot;&gt;
      &lt;h3&gt;Subjects&lt;/h3&gt;
      &lt;tr style=&quot;font-size:18px; height:30px; color:#4d4d4d&quot;&gt;
          &lt;th class=&quot;col-md-2&quot; colspan=&quot;2&quot; style=&quot;text-align:center;&quot;&gt;Category&lt;/th&gt;
          &lt;th class=&quot;col-md-3&quot; style=&quot;text-align:center;&quot;&gt;Work Scope&lt;/th&gt;
          &lt;th&gt;&lt;div style=&quot;text-align:center&quot;&gt;I&lt;/div&gt;&lt;/th&gt;
          &lt;th&gt;&lt;div style=&quot;text-align:center&quot;&gt;E&lt;/div&gt;&lt;/th&gt;
          &lt;th&gt;&lt;div style=&quot;text-align:center&quot;&gt;PI&lt;/div&gt;&lt;/th&gt;
          &lt;th&gt;&lt;div style=&quot;text-align:center&quot;&gt;PA&lt;/div&gt;&lt;/th&gt;
          &lt;th class=&quot;col-md-3&quot; style=&quot;text-align:center;&quot;&gt;ATA Chapters&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr style=&quot;height:25px; font-size:15px&quot;&gt;
          &lt;td class=&quot;col-md-1&quot; style=&quot;text-align: center; color:#4d4d4d;&quot;&gt;&lt;b&gt;Basic&lt;/b&gt;&lt;/td&gt;
          &lt;td class=&quot;col-md-1&quot;&gt;
              &lt;select style=&quot;height:30px&quot; name=&quot;basic_category[]&quot; class=&quot;form-control&quot;&gt;
                  &lt;option&gt;-&lt;/option&gt;  
                  &lt;option&gt;AP&lt;/option&gt;
                  &lt;option&gt;EA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/td&gt;
          &lt;td class=&quot;col-md-3&quot;&gt;
              &lt;div&gt;
                  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;basic_workscope[]&quot; placeholder=&quot;Type the workscope here&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div style=&quot;text-align: center&quot;&gt;
                  &lt;input type=&quot;checkbox&quot; name=&quot;basic_i[]&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div style=&quot;text-align: center&quot;&gt;
                  &lt;input type=&quot;checkbox&quot; name=&quot;basic_e[]&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div style=&quot;text-align: center&quot;&gt;
                  &lt;input type=&quot;checkbox&quot; name=&quot;basic_pi[]&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div style=&quot;text-align: center&quot;&gt;
                  &lt;input type=&quot;checkbox&quot; name=&quot;basic_pa[]&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td class=&quot;col-md-3&quot;&gt;
              &lt;div&gt;
                  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;basic_ata_chapter[]&quot; placeholder=&quot;Type the ATA chapters here&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td style=&quot;width: 20px;&quot;&gt;                                                       
              &lt;button onclick=&quot;deleteTable0()&quot; type=&quot;button&quot; class=&quot;btn btn-danger btn-sm&quot; &gt;
                  &lt;span class=&quot;glyphicon glyphicon-trash&quot;&gt;&lt;/span&gt;
              &lt;/button&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;div class=&quot;row&quot;&gt;
      &lt;button onclick=&quot;addTable0()&quot; type=&quot;button&quot; class=&quot;btn btn-success btn-sm&quot; style=&quot;float: right; margin-right: 70px;&quot;&gt;
                  &lt;span class=&quot;glyphicon glyphicon-plus&quot;&gt;&lt;/span&gt; Add
              &lt;/button&gt;
  &lt;/div&gt; 
  
  
  &lt;script&gt;    
  function addTable0()
  {
  
      var table0 = document.getElementById(&quot;myTable0&quot;);
      var row0 = table0.insertRow(2);
      var cell1_0 = row0.insertCell(0);
      var cell2_0 = row0.insertCell(1);
      var cell3_0 = row0.insertCell(2);
      var cell4_0 = row0.insertCell(3);
      var cell5_0 = row0.insertCell(4);
      var cell6_0 = row0.insertCell(5);
      var cell7_0 = row0.insertCell(6);
      var cell8_0 = row0.insertCell(7);
      var cell9_0 = row0.insertCell(8);
      row0.id = &quot;newRow_0&quot;;
      cell1_0.innerHTML = &quot;&quot;;
      cell2_0.id = &quot;cell2_0&quot;;
      cell3_0.id = &quot;cell3_0&quot;;
      cell4_0.id = &quot;cell4_0&quot;;
      cell5_0.id = &quot;cell5_0&quot;;
      cell6_0.id = &quot;cell6_0&quot;;
      cell7_0.id = &quot;cell7_0&quot;;
      cell8_0.id = &quot;cell8_0&quot;;
      cell9_0.id = &quot;cell9_0&quot;;
      $(&quot;#cell2_0&quot;).append('&lt;select style=&quot;height:30px&quot; name=&quot;basic_category[]&quot; class=&quot;form-control&quot;&gt;&lt;option&gt;-&lt;/option&gt;&lt;option&gt;AP&lt;/option&gt;&lt;option&gt;EA&lt;/option&gt;&lt;/select&gt;');
      $(&quot;#cell3_0&quot;).append('&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;basic_workscope[]&quot; placeholder=&quot;Type the workscope here&quot;&gt;');
      $(&quot;#cell4_0&quot;).append('&lt;div style=&quot;text-align: center&quot;&gt;&lt;input type=&quot;checkbox&quot; name=&quot;basic_i[]&quot;&gt;&lt;/div&gt;');
      $(&quot;#cell5_0&quot;).append('&lt;div style=&quot;text-align: center&quot;&gt;&lt;input type=&quot;checkbox&quot; name=&quot;basic_e[]&quot;&gt;&lt;/div&gt;');
      $(&quot;#cell6_0&quot;).append('&lt;div style=&quot;text-align: center&quot;&gt;&lt;input type=&quot;checkbox&quot; name=&quot;basic_pi[]&quot;&gt;&lt;/div&gt;');
      $(&quot;#cell7_0&quot;).append('&lt;div style=&quot;text-align: center&quot;&gt;&lt;input type=&quot;checkbox&quot; name=&quot;basic_pa[]&quot;&gt;&lt;/div&gt;');    
      $(&quot;#cell8_0&quot;).append('&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;basic_ata_chapter[]&quot; placeholder=&quot;Type the ATA chapters here&quot;&gt;');
      $(&quot;#cell9_0&quot;).append('&lt;button onclick=&quot;deleteTable0(this)&quot; type=&quot;button&quot; class=&quot;btn btn-danger btn-sm remove&quot; id=&quot;btn_delete&quot; &gt;&lt;span class=&quot;glyphicon glyphicon-trash&quot;&gt;&lt;/span&gt;&lt;/button&gt;');
  }
  
  function deleteTable0(r)
  {
      var i = r.parentNode.parentNode.rowIndex;
      document.getElementById(&quot;0&quot;).deleteRow(i);
  }
  &lt;/script&gt;
  </code></pre>
  <p><strong>CONTROLLER (instructor_con.php)</strong></p>
  <pre><code>$basic_data = array();
  
      $basic_category = $_POST[&quot;basic_category&quot;];
      $basic_workscope = $_POST[&quot;basic_workscope&quot;];
      $basic_i = $_POST[&quot;basic_i&quot;];
      $basic_e = $_POST[&quot;basic_e&quot;];
      $basic_pi = $_POST[&quot;basic_pi&quot;];
      $basic_pa = $_POST[&quot;basic_pa&quot;];
      $basic_ata_chapter = $_POST[&quot;basic_ata_chapter&quot;];
  
      $basic_data[] = array($id_number, $basic_category, $basic_workscope, $basic_i, $basic_e, $basic_pi, $basic_pa, $basic_ata_chapter);
  
      $this-&gt;mod-&gt;insert_t_basic($basic_data);
  </code></pre>
  <p><strong>MODEL (mod.php)</strong></p>
  <pre><code>public function insert_t_basic($basic_data) {
      if(!empty($basic_data)) {
  
          foreach($basic_data as $value) {
              $this-&gt;db-&gt;insert('t_basic', $basic_data);
          }
  
      }
  }
  </code></pre>
  <p>When I run the code above, I got this error message</p>
  <blockquote>
  <p>A PHP Error was encountered</p>
  <p>Severity: Notice</p>
  <p>Message: Array to string conversion</p>
  <p>Filename: database/DB_driver.php</p>
  <p>Line Number: 1477</p>
  </blockquote>
  <p>I have been spending 2 days trying to figure out what is the right method to insert each row data to the database. This problem seem compliated to me because I'm still new in codeigniter.</p>
  <p>If you know any soultion to my problem, please let me know. Thank you in advance :&quot;)</p>