1
我有以下代碼,其中我decrease the quantity by one
如果用戶buys
a product
。這裏的數據是stored in text files
。你會如何減少MySQL中數值列單元格的值?
現在我的問題是,如果數據存儲在MySQL中,我將如何解決這個。
基本上我想update the cell
由subtracting 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
,但它更新到0
的cell
。
請詳細說明這個問題,似乎問題需要更多的標籤。 –