【发布时间】:2015-02-16 17:12:24
【问题描述】:
我有一个脚本,我在其中获取购物车 ID,然后根据产品是否已付款来降低可用性计数。每个购物车可能包含 1 或 10 个产品,因此必须针对每个项目进行。当有人付款时(通过 PayPal IPN 确认),我正在运行:
// we set the cart id, 12345 in this case
$cart_id = '12345'
// we get the buyer ID
$buyer_id = $db->get_sql_field("SELECT buyer_id FROM db_carts WHERE sc_id='" . $cart_id . "'", "buyer_id");
// we get the products.
$sql_select_cart = $db->query("SELECT item_id, quantity FROM db_shopping_carts_items WHERE sc_id='" . $cart_id . "'");
while ($cart_details = $db->fetch_array($sql_select_cart))
{
//
foreach ($cart_details as $key => $item_details)
{
if ($item_details['quantity']<='100')
{
$db->query("UPDATE db_products SET quantity=quantity-" . $item_details['quantity'] .
" WHERE product_id='" . $item_details['item_id'] . "'");
}
}
//
}
但是,似乎什么都没有发生,我也没有收到错误消息。我在这里做错了什么?
【问题讨论】:
标签: php mysql loops while-loop