简体   繁体   English

如何使用更新批处理查询更改codeigniter中的多行

[英]how to change multiple rows in codeigniter by using update batch query

表结构 Problem: I just want to update the bill by using unique id in my database but my problem is it showing the error as undefined index id..help me to resolve this error... 问题:我只是想通过在我的数据库中使用唯一ID更新帐单,但我的问题是它显示错误为未定义的索引id ..帮助我解决此错误...

Controller Code: 控制器代码:

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);
}

Model Code: 型号代码:

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;
}

Below i have attached the error of my screenshot..Help me to fix this error 下面我附上了我的截图错误..帮我解决这个错误

在此输入图像描述

Update batch code: 更新批次代码:

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'); 

There is issue in the below code 以下代码存在问题

Update batch code: 更新批次代码:

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'); 
}

Change 'Id' => $data['billId'][$i], to 'id' => $data['billId'][$i], 'Id' => $data['billId'][$i],更改为'id' => $data['billId'][$i],

remove $this->db->where('Id',$id); 删除$this->db->where('Id',$id);

$this->db->update_batch('salesitem', $entries,'Id'); to $this->db->update_batch('salesitem', $entries,'id'); to $this->db->update_batch('salesitem', $entries,'id');

And try again. 然后再试一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM