这是我的产品表
这是我的购物车表
交易完成后,我想仅使用$new_quantity
更新我的产品表(尺寸)
我的代码如下:
$cartQ=$db->query("SELECT * FROM cart WHERE id='{$cart_id}'");
$result=mysqli_fetch_assoc($cartQ);
$items=json_decode($result['items'],true);
foreach ( $items as $item) {
$product_id = $item['id'];
$product_quantity=$item['quantity'];
$product_size=$item['size'];
$productQ = $db->query("SELECT * FROM products WHERE id='{$product_id}'");
$product = mysqli_fetch_assoc($productQ);
$productSizes=$product['sizes'];
$sArray = explode(',', $productSizes);
foreach ($sArray as $sizeString) {
$s = explode(':', $sizeString);
$size=$s[0];
$quantity=$s[1];
$threshold=$s[2];
}
}
$quantity_updateQ=$db->query("SELECT sizes FROM products WHERE id='{$product_id}'");
$quantity_update=mysqli_fetch_assoc($quantity_updateQ);
$new_quantity=intval($quantity-intval($product_quantity));
echo $new_quantity;
var_dump($product_id);
$quantity_finished=$db->query("UPDATE products SET sizes= '{$new_quantity}' WHERE id='{$product_id}'");