adam schott wrote:
i need help. i have two mysql tables. one Products table with items and a certain quantity. and the second table is a shopping cart which should include a few items from the Products table at lower quantities. what i want to do is to subtract the quantities from the shopping cart table from the quantities in the product table. i'm not quite sure how to do this. i tried this code below, but it didn't work...
//array of shopping cart items
while($row = mysql_fetch_array($cart_result)) {
$sel_item_id = $row["sel_item_id"];
$sel_item_qty = $row["sel_item_qty"];
$item_numbers = "SELECT qty FROM products WHERE id = \"$sel_item_id\"";
$number_result = mysql_query($item_numbers) or die("Couldn't get result!");
//Here is your addition
$row_number = mysql_fetch_array($number_result);
$new_number = $row[qty];
$newtotal = $new_number - $sel_item_qty;
if ($newtotal == "0") {
$sql = "DELETE products WHERE id = \"$sel_item_id\"";
$sql_result = mysql_query($sql,$connection) or die ("couldn't execute query");
} else {
$sql = ....
Ace21