title: How to insert multiple rows in mysql using codeigniter
body: <p>I want to insert multiple rows into the db using submit button,
  This is my view code</p>
  
  <pre><code>    &lt;?php   
          foreach($role_array as $k =&gt;$v)
          {
              //var_dump($k);
              if($k != "bookin_operator" &amp;&amp; $k!= "production_manager" &amp;&amp; $k != "client" &amp;&amp; $k != "admin" )
              {
  
          ?&gt;
              &lt;div class="row-fluid"&gt; 
                  &lt;div class="span6"&gt;      
                      &lt;div class='control-group'&gt;
  
  
                          &lt;label for='&lt;?php echo $k;  ?&gt;' class='control-label'&gt;&lt;?php  echo $v ;?&gt;&lt;/label&gt;
                          &lt;div class='controls'&gt;
                              &lt;select class='form-control' name='&lt;?php echo $k;  ?&gt;[]' id='&lt;?php echo $k;  ?&gt;' multiple='multiple' size='5'&gt;
                                  &lt;?php
  
                                     foreach($all_datas[$k] as $datas ) 
                                     {
  
                                          $username = "{$datas-&gt;nickname}";
  
                                          echo "&lt;option value='{$datas-&gt;id}'&gt;{$username}&lt;/option&gt;";
                                     }
                                  ?&gt;
                              &lt;/select&gt;
                              &lt;label for="&lt;?php echo $k;  ?&gt;" class="error" style="display:none"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;                         
                  &lt;/div&gt;    
  
              &lt;/div&gt;  
              &lt;?php }} ?&gt; 
  </code></pre>
  
  <p>This is my controller code</p>
  
  <pre><code>            $roles = $this-&gt;utility-&gt;roles;
              foreach($roles as $k =&gt; $v)
              {
                  if($k != "bookin_operator" &amp;&amp; $k!= "production_manager" &amp;&amp; $k != "client" &amp;&amp; $k != "admin" &amp;&amp; isset($post_data[$k]))
                  {
                      $userrole = $k;
                      $post_user=isset($post_data[$k])?$post_data[$k]:'';
  
                      if (count($post_user) &gt; 0)
                      {
                          for ($i = 0; $i &lt; count($post_user); $i++)
                          {
                              $data = array("journal_id" =&gt; $new_journal_id,"user_role" =&gt; $userrole,"user_id" =&gt;$post_user[$i]);
                             // var_dump($data);
                              $flag = true;
  
  
  
                          }
                      }
                  }
              }
  
              if(isset($flag))
              {
  
                  $v=$this-&gt;JournalUsers-&gt;addJournalUser($data);
              }
  </code></pre>
  
  <p>$data output is </p>
  
  <pre><code>    array(3) {
      ["journal_id"]=&gt;int(83)
      ["user_role"]=&gt;
      string(15) "quality_checker"
      ["user_id"]=&gt;
      string(3) "136"
      }
      array(3) {
      ["journal_id"]=&gt;
      int(83)
      ["user_role"]=&gt;
      string(5) "texer"
      ["user_id"]=&gt;
      string(3) "103"
      }
      array(3) {
      ["journal_id"]=&gt;
      int(83)
      ["user_role"]=&gt;
      string(5) "texer"
      ["user_id"]=&gt;
      string(3) "133"
      }
       array(3) {
      ["journal_id"]=&gt;
      int(83)
      ["user_role"]=&gt;
      string(5) "texer"
      ["user_id"]=&gt;
      string(3) "132"
      }
      array(3) {
     ["journal_id"]=&gt;
     int(83)
     ["user_role"]=&gt;
     string(10) "typesetter"
     ["user_id"]=&gt;
     string(3) "109"
     }
  
     array(3) {
     ["journal_id"]=&gt;
     int(83)
     ["user_role"]=&gt;
     string(10) "typesetter"
     ["user_id"]=&gt;
     string(3) "153"
     }
  </code></pre>
  
  <p>But,when insert the data only one row will be inserted on the table.   </p>
  
  <pre><code>   array(3) {
     ["journal_id"]=&gt;
     int(83)
     ["user_role"]=&gt;`enter code here`
      string(10) "typesetter"
      ["user_id"]=&gt;
      string(3) "153"
      }  
  </code></pre>
  
  <p>I want to insert all datas in db</p>