title: Inserting multiple values in database codeigniter?
body: <p>I want to insert multiple rows in the database on one click if row is checked using multiple checkbox
  <img src="https://i.stack.imgur.com/ypcYL.png" alt="enter image description here"></p>
  
  <p>Here is my code=>
  1)Controller: <code>guard.php</code>
  (Here I take a array of list of student id's and pass them one by one to the another function get_leave_data which take id of a student and return more information about the student from another table <code>leave_application</code>).</p>
  
  <pre><code>public function students_out(){
      $request=$this-&gt;input-&gt;post('approve_leave_status');
      if($request=="OUT"){
      $check_list_out[]=$_POST['check_list_out'];
      if(!empty($check_list_out)){
            foreach ($check_list_out as $check_list_id) {
              $student_data=$this-&gt;get_leave_data($check_list_id);
              $this-&gt;insert_student_outside($student_data);
            }
            $this-&gt;load-&gt;helper('url');
            $this-&gt;load-&gt;view('view_guard');
      }
  }else{
       $this-&gt;load-&gt;helper('url');
       $this-&gt;load-&gt;view('view_guard');
  }
  
  } `
  
   public function get_leave_data($id){
   $this-&gt;load-&gt;model('model_guard');
   $data=$this-&gt;model_guard-&gt;get_data($id);
   return $data;
  }
  
  public function insert_student_outside($std_data){
    $this-&gt;load-&gt;model('model_guard');
    $data=$this-&gt;model_guard-&gt;insert_student_out($std_data);
   return $data;
  }
  </code></pre>
  
  <p>2)Model: model_guard.php
  (The functions <code>get_data()</code> and <code>get_data2()</code> return more informations about student and function <code>insert_student_out()</code> insert the student to the <code>student_outside table</code>)</p>
  
  <pre><code>public function get_data($id){
      $this-&gt;db-&gt;select('leave_id,leave_from_roll_no,leave_student_name,leave_going_to,leave_from_date,leave_till_date,leave_hostel_no,leave_status');
      $this-&gt;db-&gt;from('leave_application');
      $this-&gt;db-&gt;where('leave_id',$id[0]);
      $query=$this-&gt;db-&gt;get();
      $data1=$query-&gt;result();
      $data2=$this-&gt;get_data2($data1);
      $final_array=array_merge($data1,$data2);
      return $final_array;
      }
  
      public function get_data2($array){
      foreach ($array as $key) {
      $roll_no=$key-&gt;leave_from_roll_no;
      }
      $this-&gt;db-&gt;select('student_year,student_semester,student_parent_email');
      $this-&gt;db-&gt;from('students');
      $this-&gt;db-&gt;where('student_roll_no',$roll_no);
      $query=$this-&gt;db-&gt;get();
      $data=$query-&gt;result();
      return $data;
      }
  
      public function insert_student_out($std_data){
      $roll_no=$std_data[0]-&gt;leave_from_roll_no;
      $id=$std_data[0]-&gt;leave_id;
      $date_out=date('Y-m-d');
      $inside_date=NULL;
      $date_allowed=$std_data[0]-&gt;leave_till_date;
      $array=array(
      'outside_id'=&gt;$id,
      'outside_roll_no'=&gt;$roll_no,
      'outside_date_out'=&gt;$date_out,
      'outside_date_in'=&gt;$inside_date,
      'outside_date_allowed'=&gt;$date_allowed
      );
      if($this-&gt;db-&gt;insert('students_outside',$array)){
          return true;
      }else{
          false;
      }
  
  
      }
  </code></pre>