2013-08-27 17 views
8

Merhaba çocuklar nasıl İşte benim örnek kod var CodeIgniter dizileri kullanarak bir toplu güncelleştirme gerçekleştirebilirsiniz:Codeigniter dizilerini kullanarak toplu güncelleştirme nasıl yapılır? Sadece sormak istiyorum

public function updateItemInfo(){ 

     $id = $this->input->post('idx'); //array of id 
     $desc = $this->input->post('itemdesc'); //array of item name 
     $qty = $this->input->post('qty'); //array or qty 
     $price = $this->input->post('price'); //array of price 
     $code = $this->input->post('codes'); // not array 

     for($x = 0; $x < sizeof($id); $x++){ 

      $total[] = $price[$x] * $qty[$x]; 

      $updateArray = array(
       'item_desc' => $desc[$x], 
       'item_qty' => $qty[$x], 
       'price' => $price[$x], 
       'total' => $total 
      ); 
      $this->db->where('poid',$id[$x]); 
      $this->db->update('po_order_details',$updateArray); //Could not update I don't know why 

     } 

     //echo "<pre>"; 
     //print_r($updateArray); 


     $sumoftotal = array_sum($total); 

     $vat_amt = $sumoftotal/1.12; 
     $vat_input = $vat_amt * 0.12; 
     $total_all = $vat_amt + $vat_input; 

     $updateTotal = array(
      'vatable_input' => $vat_amt, 
      'vatable_amount' => $vat_input, 
      'total_amount_due' => $total_all 
     ); 

     //echo "<pre>"; 
     //print_r($updateTotal); 

     //exit; 

     $this->db->where('order_code',$code); 
     $this->db->update('po_order_total',$updateTotal); //Here also couldn't update 

    } 

benim kod Ve hata nerede ben onu anladım olamaz. Ayrıca dizi değerlerimi de kontrol ettim ve dizimde bir hata yok. Sorunum, toplu güncellemeyi kullanarak tablomu güncelleyemem. http://ellislab.com/codeigniter/user-guide/database/active_record.html

CodeIgniter 3.x: http://www.codeigniter.com/user_guide/database/query_builder.html?highlight=where#CI_DB_query_builder::update_batch

Sen tüm seçeneği ile bir array oluşturabilir ve daha sonra batch_update işlevine gönderme

+0

Yaz '$ echo this-> db-> last_query(); die;' Bu satırdan sonra: '$ this-> db-> bilgi ('po_order_details', $ updateArray); // Güncellenemedi Sorunun hangi nedenle oluşturulduğunu bilmiyorum. –

cevap

16

deneyin burada update_batch seçeneği görmek için.

$id = $this->input->post('idx'); //array of id 
$desc = $this->input->post('itemdesc'); //array of item name 
$qty = $this->input->post('qty'); //array or qty 
$price = $this->input->post('price'); //array of price 
$code = $this->input->post('codes'); // not array 

$updateArray = array(); 

for($x = 0; $x < sizeof($id); $x++){ 

    $total[] = $price[$x] * $qty[$x]; 
    $updateArray[] = array(
     'poid'=>$id[$x], 
     'item_desc' => $desc[$x], 
     'item_qty' => $qty[$x], 
     'price' => $price[$x], 
     'total' => $total 
    ); 
}  
$this->db->update_batch('po_order_details',$updateArray, 'poid'); 
+0

ok teşekkürler bunu deneyeceğim. – Jerielle

+0

$ this-> db-> update_batch ('po_order_details', $ updateArray, 'poid'); benim için mi? – Jerielle

+0

Üzgünüz, işte bunun için() –

İlgili konular