2017-12-03 106 views
1

我有以下代碼,其中我decrease the quantity by one如果用戶buys a product。這裏的數據是stored in text files你會如何減少MySQL中數值列單元格的值?

現在我的問題是,如果數據存儲在MySQL中,我將如何解決這個

基本上我想update the cellsubtracting 1從它的價值。例如,如果quantity = 200,我想更新到quantity = 199

for($i = 0; $i < count($ajProducts) ; $i++) { 
    if ($sProductId == $ajProducts[$i]->id) { 
     //check if the value of the id is equal to the value in the array. 

     $ajProducts[$i]->quantity = $ajProducts[$i]->quantity-1; 

     //increase the quanity of the object by one if there is a match ; 
    } 
} 

我已經開始用這樣的事情:UPDATE products SET quantityInStock=-1 WHERE productCode=':productCode,但它更新到0cell

+0

請詳細說明這個問題,似乎問題需要更多的標籤。 –

回答

2

只需設置quantityInStock = quantityInStock - 1這樣

UPDATE products SET quantityInStock=quantityInStock-1 WHERE productCode=':productCode