How to input several row of data into sql.My code only input the first set of data
controller page:
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>";
}
}
model page :
function savedata($jdata, $machine_name)
{
if($machine_name=="machine1"){
$adata = array($jdata);
$this->db->insert_batch('table1',$adata);
return true;
}
data retrieved but only first set of data insert into sql.From my understanding insert_batch must be in array thats why I array the json data
CodePudding user response:
Im so sorry I just discover my own problem.Its my json api I make it parse_data[0]
instead of parse_data
thats why it only insert first set of data..so in model it should be $this->db->insert_batch('display_da_silo4',$jdata); return true;
thank you for telling me to validate data ;)