我正在動態獲取數組值,但我無法將數組值作爲單獨的行添加到codeigniter中的MySQL數據庫中。將每個數組值插入codeigniter中從控制器到模型的單獨行
從Ajax的輸出是1000乙400
控制器
$myTableArray = json_decode($_POST['myTableArray'], true);
$appointment_id=$this->user_model->get_details();
$details=$this->user_model->patient_investigation_details($myTableArray,$appointment_id);
模型
function get_details()
{
$this->db->trans_start();
$query = $this->db->query("SELECT * from `appointment_details` ORDER BY `appointment_id` DESC");
$this->db->trans_complete();
if($query->num_rows()>=1)
return $query->result()[0]->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->db->trans_start();
$query = $this->db->query($query_string);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE){
return null;
}
else{
return TRUE;
}
}
請問您是否可以驗證下面的代碼? –