简体   繁体   中英

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...

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],

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

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

And try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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