I had the same problem as you, and I solved it like this: 1-Delete all the entries of the user you want, and donβt insert the package like a code hit.
$employer_office = $this->input->post('employer_office'); $emp_job_type = $this->input->post('job_type'); $job_title = $this->input->post('job_title'); $job_appointment_date = $this->input->post('job_appointment_date'); $job_duration = $this->input->post('job_duration'); $job_place = $this->input->post('job_place'); $type_of_relation = $this->input->post('type_of_relation'); $monthly_salary = $this->input->post('monthly_salary'); $remarks = $this->input->post('remarks'); $all_array = array(); if($employer_office) { if(is_array($employer_office)) { for($j=0; $j<count($employer_office); $j++) { $form_arr = array( 'employer_office' =>$employer_office[$j], 'job_type' =>$emp_job_type[$j], 'job_title' =>$job_title[$j], 'job_appointment_date' =>change_datei($job_appointment_date[$j]), 'job_duration' =>$job_duration[$j], 'job_place' =>$job_place[$j], 'type_of_relation' =>$type_of_relation[$j], 'monthly_salary' =>$monthly_salary[$j], 'remarks' =>$remarks[$j], 'regdate' =>date('Ymd H:m:s'), 'userid' =>$id ); array_push($all_array, $form_arr); } } } if($this->history_model->delete_all('ast_jobs_history', $id)==TRUE) { if($this->history_model->all_insert('ast_jobs_history', $all_array)==TRUE) { $this->session->set_flashdata("msg","<span class='m_success'>".$this->lang->line('global_update_success')."</span>"); redirect('history/home/list_dy','refresh'); } else { $this->session->set_flashdata("msg","<span class='m_error'>".$this->lang->line('global_update_error')."</span>"); redirect('history/home/list_dy','refresh'); } } else { $this->load->view('unauthorized'); }
and inside the insert_batch it model.
function all_insert($tbl, $data=array()) { if(is_array($data)) { $this->db->trans_start(); $this->db->insert_batch($tbl,$data); $this->db->trans_complete(); return TRUE; } else { return FALSE; } }
make some changes, and I hope this gives you a hint on how to solve your problem.
or you can also make a request if you do not want to delete records of a specific identifier, get data according to the identifier and use the array_search () or in_array () function to filter your published data and get the record that you want to insert, and then paste it into the database data.
source share