sql中如何輸入多行資料,我的代碼只輸入了第一組資料
控制器頁面:
public function all_report(){
if($this->input->post('save'))
{
$machine_name = $this->input->post('device_type');
$jdata = json_decode($this->input->post('my_data'));
$response=$this->post_model->savedata($jdata, $machine_name);
if($response==true){
$message = "Data import Successfully";
echo "<script>alert('$message');</script>";
}
else{
$message = "Data import Fail";
echo "<script>alert('$message');</script>";
}
}
模型頁面:
function savedata($jdata, $machine_name)
{
if($machine_name=="machine1"){
$adata = array($jdata);
$this->db->insert_batch('table1',$adata);
return true;
}
檢索到的資料,但只有第一組資料插入到 sql.從我的理解 insert_batch 必須在陣列中,這就是我排列 json 資料的原因


uj5u.com熱心網友回復:
我很抱歉,我只是發現了我自己的問題。這是我的 json api 我做的parse_data[0]而不是parse_data這就是為什么它只插入第一組資料..所以在模型中應該$this->db->insert_batch('display_da_silo4',$jdata); return true;感謝你告訴我驗證資料;)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397976.html
