So in theory this should work right?
function updateCart($id) {
// Updates the cart
$query = db_query("SELECT * FROM store_cart WHERE user = $id");
while($check == db_fetch_object($query)) {
// Checks the size in the cart
if ($check->size == "Youth") {
$quantity = "quantity_1";
} elseif ($check->size == "Small") {
$quantity = "quantity_2";
} elseif ($check->size == "Medium") {
$quantity = "quantity_3";
} elseif ($check->size == "Bag") {
$quantity = "quantity_0"; }
// Finds the item with the cart and user
$query = db_query("SELECT id, $quantity FROM store_product WHERE id = $check->id_pro");
while($left == db_fetch_object($query)) {
// If quantity in there cart is greater then quantity left
if ($check->quantity > $left->$quantity) {
// Drop the cart if no product quantity left
if ($left->$quantity == 0) {
$query = db_query("DELETE FROM store_cart WHERE id = $check->id");
// If product quantity is 1, set there quantity to 1
} elseif ($left->$quantity == 1) {
$query = db_query("UPDATE store_cart SET quantity = 1 WHERE id = $check->id AND id_pro = $left->id AND user = $id");
}
}
}
}
}
Edited by tiki, 18 January 2006 - 12:22 AM.
