问题: 我只想通过在数据库中使用唯一ID来更新帐单,但我的问题是它将错误显示为未定义的索引ID。请帮助我解决此错误...
控制器代码:
public function Bill_Edit()
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$query = $this->db->get('parmaster');
$data['PName']=$query->result_array();
$data['r'] = $this->User_model->Bill_Edit1();
$data['result'] =$this->User_model->Bill_Edit();
$this->load->view('Inventory/Bill_Edit',$data);
}
型号代码:
public function Bill_Edit()
{
$Search = $this->input->post('Search');
$this->db->where('billno', $Search);
$this->db->select('*');
$this->db->from('salesitem');
$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
$query = $this->db->get()->result_array();
return $query;
}
public function Bill_Edit1()
{
$Search = $this->input->post('Search');
$this->db->where('billno', $Search);
$this->db->select('*');
$this->db->from('salesitem');
$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
$query = $this->db->get()->row();
return $query;
}
下面我附上了我的屏幕截图错误。帮助我修复此错误
更新批处理代码:
public function Bill_Update($data)
{
$LDate = $this->input->post('TDate');
$date = str_replace('/', '-', $LDate);
$newDate = date("Y-m-d", strtotime($date));
$id =$this->input->post('billid');
$billno = $this->input->post("billno");
$data = $this->input->post();
$count = count($data['Product_Code']);
for($i = 0; $i<$count; $i++){
$entries[] = array(
'Id' => $data['billId'][$i],
'Product_Code'=>$data['Product_Code'][$i],
'Prdtname'=>$data['Prdtname'][$i],
'Qty'=>$data['Qty'][$i],
'rate'=>$data['rate'][$i],
'billdate'=>$newDate,
'amount'=>$data['amount'][$i]
);
}
$this->db->where('Id',$id);
$this->db->update_batch('salesitem', $entries,'Id');
答案 0 :(得分:0)
下面的代码有问题
更新批处理代码:
public function Bill_Update($data)
{
$LDate = $this->input->post('TDate');
$date = str_replace('/', '-', $LDate);
$newDate = date("Y-m-d", strtotime($date));
$id =$this->input->post('billid');
$billno = $this->input->post("billno");
$data = $this->input->post();
$count = count($data['Product_Code']);
for($i = 0; $i<$count; $i++){
$entries[] = array(
'Id' => $data['billId'][$i],
'Product_Code'=>$data['Product_Code'][$i],
'Prdtname'=>$data['Prdtname'][$i],
'Qty'=>$data['Qty'][$i],
'rate'=>$data['rate'][$i],
'billdate'=>$newDate,
'amount'=>$data['amount'][$i]
);
}
$this->db->where('Id',$id);
$this->db->update_batch('salesitem', $entries,'Id');
}
更改
'Id' => $data['billId'][$i],
到 'id' => $data['billId'][$i],
删除 $this->db->where('Id',$id);
$this->db->update_batch('salesitem', $entries,'Id');
到 $this->db->update_batch('salesitem', $entries,'id');
然后重试。