title: Inserting each array value as a seperate row in codeigniter from controller to model
body: <p>I am getting array values dynamically but I am not able add the array values as a separate row into the MySQL database in codeigniter.</p>
  
  <p>The output from Ajax is A 1000 B 400</p>
  
  <p><strong>Controller</strong> </p>
  
  <pre><code>$myTableArray = json_decode($_POST['myTableArray'], true);
  
  $appointment_id=$this-&gt;user_model-&gt;get_details();
  
  $details=$this-&gt;user_model-&gt;patient_investigation_details($myTableArray,$appointment_id);
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>function get_details()
  {
    $this-&gt;db-&gt;trans_start();
    $query = $this-&gt;db-&gt;query("SELECT * from `appointment_details` ORDER BY `appointment_id` DESC");
    $this-&gt;db-&gt;trans_complete();
    if($query-&gt;num_rows()&gt;=1)
      return $query-&gt;result()[0]-&gt;appointment_id;
  }
  
  function patient_investigation_details($myTableArray,$appointment_id)
  {
    $query_string="INSERT into `patient_investigation_details`(`investigation_name`,`price`,`appointment_id`) VALUES";
    foreach ($myTableArray as $row)
    {
      $query_string.="('".$row['1']."','". $row['2']."','".$appointment_id."')";
    }
    $this-&gt;db-&gt;trans_start();
    $query = $this-&gt;db-&gt;query($query_string);
    $this-&gt;db-&gt;trans_complete();
  
    if ($this-&gt;db-&gt;trans_status() === FALSE){
     return null;
    }
    else{
     return TRUE;
    } 
  }
  </code></pre>