我遇到了同样的问题,有些像你,我像这样解决了它:1-删除你想要的用户的所有记录,然后像代码一样插入批处理。
$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('Y-m-d 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');
}
并在模型 insert_batch 内。
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;
}
}
带来一些改变,我希望这会给你一个关于如何解决你的问题的提示。
或者如果您不想删除特定ID的记录,也可以进行查询,根据ID获取数据并使用array_search()或in_array()函数过滤您发布的数据并获取您要插入的记录它,而不是将其插入数据库。