我有一个db表(商业提案的表单表),该表已经用默认行归档,我想执行多次更新查询,将默认值从代码点火器中的submit with post方法更改为插入值。。我已经建立了一个函数save_report()
。
我尝试过使用$this->db->update_batch();
,它只对第一个foreach循环执行。。
function save_report(){
$data['old_circle'] = $this->input->post('old_circle');
$data['sold'] = $this->input->post('sold');
$data['diffrent_come'] = $this->input->post('diffrent_come');
$data['total'] = $this->input->post('total');
$data['new_circle'] = $this->input->post('new_circle');
$data['sold_start_month'] = $this->input->post('sold_start_month');
$data['bought_start_month'] = $this->input->post('bought_start_month');
$data['paid_start_month'] = $this->input->post('paid_start_month');
foreach($data as $key=>$value){
$comp = array('sold_start_month','bought_start_month','paid_start_month');
if(in_array($key,$comp)){
$this->db->where(array('report_id'=>1,'name' =>$key));
$this->db->update('reports_det',array('value'=>$value));
}
$update_array[] = array(
'name' =>$key,
'recived' =>$value['recived'],
'paid' =>$value['paid'],
'recived_bill'=>$value['recived_bill'],
'paid_bill' =>$value['paid_bill']
);
$this->db->where(array('report_id'=>1));
$this->db->update_batch('reports_det',$update_array,'name');
}
redirect('c_panel/reports_det_mangment/1');
}
非常感谢。。
很抱歉浪费了你们的时间,昨天我在工作中注意力不集中,所以今天我真的很专注哈哈,问题是我没有为每个post数组设置foreach循环,最终答案是:
function save_report(){
$report_id = $this->input->post('rid');
if(count($_POST) > 0){
$data['old_circle'] = $this->input->post('old_circle');
$data['sold'] = $this->input->post('sold');
$data['diffrent_come'] = $this->input->post('diffrent_come');
$data['total'] = $this->input->post('total');
$data['new_circle'] = $this->input->post('new_circle');
$data['sold_start_month'] = $this->input->post('sold_start_month');
$data['bought_start_month'] = $this->input->post('bought_start_month');
$data['paid_start_month'] = $this->input->post('paid_start_month');
foreach($data['old_circle'] as $key=>$value){
$this->db->where(array('report_id'=>$report_id,'name' =>'old_circle'));
$this->db->update('reports_det',array($key=>$value));
}
foreach($data['sold'] as $key=>$value){
$this->db->where(array('report_id'=>$report_id,'name' =>'sold'));
$this->db->update('reports_det',array($key=>$value));
}
foreach($data['diffrent_come'] as $key=>$value){
$this->db->where(array('report_id'=>$report_id,'name' =>'diffrent_come'));
$this->db->update('reports_det',array($key=>$value));
}
foreach($data['total'] as $key=>$value){
$this->db->where(array('report_id'=>$report_id,'name' =>'total'));
$this->db->update('reports_det',array($key=>$value));
}
foreach($data['new_circle'] as $key=>$value){
$this->db->where(array('report_id'=>$report_id,'name' =>'new_circle'));
$this->db->update('reports_det',array($key=>$value));
}
foreach($data['sold_start_month'] as $value){
$this->db->where(array('report_id'=>$report_id,'name' =>'sold_start_month'));
$this->db->update('reports_det',array('value'=>$value));
}
foreach($data['bought_start_month'] as $value){
$this->db->where(array('report_id'=>$report_id,'name' =>'bought_start_month'));
$this->db->update('reports_det',array('value'=>$value));
}
foreach($data['paid_start_month'] as $value){
$this->db->where(array('report_id'=>$report_id,'name' =>'paid_start_month'));
$this->db->update('reports_det',array('value'=>$value));
}
}
redirect('c_panel/reports_det_mangment/'.$report_id);
}