你会如何减少MySQL中数值列单元格的值?
我有以下代码,其中我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。
回答:
只需设置quantityInStock = quantityInStock - 1这样
UPDATE products SET quantityInStock=quantityInStock-1 WHERE productCode=':productCode 以上是 你会如何减少MySQL中数值列单元格的值? 的全部内容, 来源链接: utcz.com/qa/259754.html

