2016-07-13 11 views
0

花了幾個小時和衆多谷歌搜索,我仍然無法得到這個解決方案。 請幫助檢查什麼,我在此代碼做錯了:Codeigniter主動查詢:多個更新相同的列不同的行不同在哪裏ID

   $product = $this->site->getProductByID($item['product_id']); 
       $inventory = $this->site->getInventoryByID($product->id); 

       if($pp_up === TRUE && (($product->quantity < 0) && ($product->parent_id != 0) && ($inventory->box_qty != 0)) === TRUE){ 

       $s_Update = array(
        'quantity' => ($product->quantity+$inventory->qty_per_box), 
        'id' => $inventory->ea_id 
        ); 
        $this->db->where('id',$inventory->ea_id); 
        $this->db->update('products',$s_Update); 

     // the query runs successfully up till here------------------------------------ 

      /*This Never perform any update */ 
        if($this->db->affected_rows() > 0){ 

    $this->db->update('products', array('quantity' => ($product->quantity-1), array('id' => $inventory->box_id))); 

第一次更新工作順利,並根據更新表。但是,第二次更新對錶格沒有影響。

請幫助正確的方向。

我真的很希望這真的很清楚,能夠幫助我。

謝謝你們。

+0

表中數量字段的數據類型是不是整數? – pradeep

+0

quantity is varchar not integer –

+0

put this $ sql ='update products set quantity ='。($ product-> quantity-1)。'其中id ='。$ inventory-> box_id;之前更新查詢和回聲這個SQL來看看輸出是什麼 – pradeep

回答

0

做到這一點;

$s_Update = array('quantity' => ($product->quantity+$inventory->qty_per_box)); 
$this->db->where('id',$inventory->ea_id); 
$this->db->update('products',$s_Update); 

$quantity = $product->quantity-1; 
$data = array('quantity'=> $quantity); 

$this->db->where('id', $inventory->box_id); 
$this->db->update('products', $data); 
+0

這會執行兩次更新,但會出現錯誤,而不是從$ product-> quantity中減去1,其中id = $ inventory- > box_id,它只在數量列中插入「-2」。我已經嘗試了在表格中使用不同$ product->數量的多個ID。同樣的問題。 (插入-2)。 –

+0

我已經接受了這個答案。有用。但是,我只需在第一次更新後使用$ inventory-> box_id再次獲取$ product-> quantity並結束heachaches。感謝老闆指點我正確的方向。 –

相關問題