2013-08-27 8 views
8

Hallo Leute, ich möchte nur fragen, wie kann ich eine Batch-Update mit Arrays in CodeIgniter ausführen Hier ist mein Beispielcode:Wie führe ich eine Batch-Aktualisierung mit Codeigniter-Arrays durch?

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 

    } 

, dass mein Code ist Und ich kann es nicht herausgefunden, wo mein Fehler ist. Ia überprüft auch meine Array-Werte und es gibt keinen Fehler in meinem Array. Mein Problem ist, dass ich meine Tabelle nicht mit Batch-Update aktualisieren kann. 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

Sie können eine array mit allen Option erstellen und dann schicken Sie es an die batch_update Funktion

+0

schreiben 'echo $ this-> db-> last_query(); sterben;' nach dieser Zeile: '$ this-> db-> update ('po_order_details', $ updateArray); // Ich konnte nicht aktualisieren, ich weiß nicht warum, um zu sehen, welche Anfrage generiert wurde. –

Antwort

16

Try update_batch Option hier zu sehen.

$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 danke ich werde das versuchen. – Jerielle

+0

ist das $ this-> db-> update_batch ('po_order_details', $ updateArray, 'poid'); in meiner for-Schleife? – Jerielle

+0

Es tut mir leid, es ist nach der für() –

Verwandte Themen