2013-08-27 6 views
8

हैलो दोस्तों मैं सिर्फ पूछना चाहता हूँ मैं एक बैच अद्यतन CodeIgniter में सरणियों का उपयोग कर यहाँ मेरी नमूना कोड कैसा प्रदर्शन करते हैं:कोडनिर्देशक सरणी का उपयोग कर बैच अपडेट कैसे करें?

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 

    } 

मेरी कोड है कि और मैं यह समझ नहीं कर सकते बाहर जहाँ मेरे त्रुटि है। Ia ने भी मेरे सरणी मानों की जांच की और मेरी सरणी में कोई त्रुटि नहीं है। मेरी समस्या यह है कि मैं बैच अपडेट का उपयोग करके अपनी तालिका अपडेट नहीं कर सकता। 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

आप अपने सभी विकल्प के साथ एक array बना सकते हैं और फिर इसे batch_update कार्य करने के लिए भेज सकते हैं

+0

लिखें '$ गूंज इस-> db-> last_query(); मर;' इस लाइन के बाद: '$ this-> db-> अपडेट ('po_order_details', $ updateArray); // अपडेट नहीं किया जा सका मैं नहीं जानता कि क्यों देखें कि कौन सी क्वेरी उत्पन्न हुई है। –

उत्तर

16

कोशिश update_batch विकल्प यहाँ देखने के लिए।

$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

ठीक है धन्यवाद मैं कोशिश करूँगा। – Jerielle

+0

यह $-> डीबी-> अपडेट_बैच ('po_order_details', $ updateArray, 'poid') है; लूप के लिए मेरे अंदर? – Jerielle

+0

कोई खेद नहीं है, इसके बाद() –

संबंधित मुद्दे