title: Inserting multiple checkbox values with a same text field value (codeigniter)
body: <p>I'm trying to put values into a MySQL table like this one:</p>
  
  <h1>|---sbjct_name---|---level---| </h1>
  
  <p>|---------- Physics ----------|----Level 1-----|</p>
  
  <p>|---------- Physics ----------|----Level 2-----|</p>
  
  <p>|---------- Physics ----------|----Level 3-----|</p>
  
  <p>|---------- Calculus ---------|----Level 1-----|</p>
  
  <p>|---------- Calculus ---------|----Level 2-----|</p>
  
  <p>(I don't know how to make table but I guess u get the idea)</p>
  
  <p>Let say I'm going to put "Math" into sbjct_name column alongside with "Level 1", "Level 2", "Level 3" values into the level column.</p>
  
  <p>The basic idea is from <a href="http://i.stack.imgur.com/05Vds.png" rel="nofollow">this pict (selecting value for a same input text value)</a>. </p>
  
  <p>Instead of inserting "Math" multiple times for each level,
  I'm trying to make it one time submit with checkbox tag. It will be something like <a href="http://i.stack.imgur.com/oaTRe.png" rel="nofollow">this pict (with checkbox)</a>.</p>
  
  <p>I don't have any idea how to make this happen (or if it possible in CI).</p>
  
  <p>This is some code from my Controller,</p>
  
  <pre><code>public function add_subject()
  {
      $data = array();
  
      if ($this-&gt;input-&gt;post('savebttn'))
      {
          $this-&gt;form_validation-&gt;set_rules('sbjct_name', 'Subject Name', 'trim|required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('level', 'Level', '|required|is_natural');
          $this-&gt;form_validation-&gt;set_error_delimiters('&lt;span class="fielderror"&gt;','&lt;/span&gt;');
  
          if ($this-&gt;form_validation-&gt;run() == FALSE)
          {
              $data['reset'] = FALSE;
          }
          else
          {
             //I don't know what to do here
             //I don't know what to do here
             //I don't know what to do here
             //I don't know what to do here
          }
      }
      $data['level'] = $this-&gt;admin_model-&gt;get_checkbox_option('level', 'lvl_id', 'lvl_name');
      $data['page'] = 'createsubject';
      $this-&gt;load-&gt;view('admin/main', $data);
  }
  </code></pre>
  
  <p>This is a checkbox view function in the Model,</p>
  
  <pre><code>public function get_checkbox_option($table, $id, $name, $selected=0)
  {
      $query = $this-&gt;db-&gt;get($table);
      $select= '';
      if ($query-&gt;num_rows() &gt; 0)
      {
          foreach ($query-&gt;result_array() as $row)
          {
              $selected_option = ($selected == $row[$id]) ? 'selected = "selected" ':' ';
              $select .='&lt;input type="checkbox" name="level" value="'.$row[$id].'" '.$selected_option.'&gt;'.$row[$name].'&lt;br&gt;';
          }
      }
      return $select;
  }
  </code></pre>
  
  <p>This is the form on the View,</p>
  
  <pre><code>    &lt;form action="" method="post" id="createcategoryform"&gt;
          &lt;table&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;div class="label"&gt;Subject Name&lt;/div&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;div class="input"&gt;
                          &lt;input type="text" name="sbjct_name" size="39" class="ui-corner-all input-text validate[required]"&gt;
                          &lt;?=form_error('sbjct_name');?&gt;
                      &lt;/div&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;div class="label"&gt;Level&lt;/div&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;div class="input-text ui-corner-all validate[required]"&gt;
                          &lt;?=(isset($level)) ? $level: '';?&gt;
                      &lt;/div&gt;&lt;?=form_error('level');?&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="submit" value="Save" name="savebttn" class="input-button ui-corner-all ui-state-default"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>I will be grateful if you can give any clue. :D</p>