title: insert data checked in data table checkbox codeigniter
body: <p>I am doing a project for my school subject. I am confused on how to do checking data's in checkbox and when I press a submit button, it will loop to insert into my database. I manage to display/alert the data that is being checked in my data-table.</p>
  
  <p>Here is my Contoller where it populates my data table:</p>
  
  <pre><code>public function getalldocs() {
      $listdocs = $this-&gt;Admin_model-&gt;getdoctors();
      $data = array();
      foreach ($listdocs as $docs) {
          $row = array();  
          $row[] = $docs-&gt;user_fname;
          $row[] = $docs-&gt;user_mname;
          $row[] = $docs-&gt;user_lname;
          $row[] = '&lt;input name="user_id[]" value="'.$docs-&gt;user_id.'" type="checkbox"&gt;';
  
          $data[] = $row;
      }
      $output = array(   
          "data" =&gt; $data,
      );
      echo json_encode($output);
  }
  </code></pre>
  
  <p>Here is in my view:</p>
  
  <pre><code>&lt;div class="dataTable_wrapper"&gt;
      &lt;table id="dataTables-docs"  class="table table-striped table-bordered table-hover dataTable dtr-inline" role="grid" style="width: 100%;" width="100%" aria-describedby="dataTables-material"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Middle Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;&lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;&lt;!-- dataTable_wrapper --&gt;
  </code></pre>
  
  <p>here is my javascript to echo the selected check box from my data-table:</p>
  
  <pre><code>function show_docs() {
      $("#dataTables-docs").dataTable().fnDestroy();
      table =  $('#dataTables-docs').DataTable({
          "ajax": {
              "url": "&lt;?php echo site_url('admin_controls/getalldocs')?&gt;",
              "type": "POST",
          },
          responsive: true,
          className: 'select-checkbox',
          'bInfo': false,
          'paging': false
      });
  }
  
  $('#dataTables-docs tbody').on('click', 'input[type="checkbox"]', function(e){
      var user_id = $(this).val();
      alert(user_id);
  });
  </code></pre>
  
  <p>now, i want to all that is being checked to be inserted in my database like this:
  (myid,selectedfromcheckbox);
  here is my screenshot from database table:
  <a href="https://i.stack.imgur.com/yta5m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yta5m.png" alt="enter image description here"></a></p>