i'm working on a shopping cart system and i have finished most of the main stuff. i just have a few dumb details left. the product is one that is unique in that each time an item is purchased, it must be deleted from the product database(mysql). the only way i can think to do this is with a while loop and a mysql query (which won't work). please help in an alternative method to deleting all products with a unique product id each time one is purchased. for some help, here is my while loop (i know you can't run a query in a while loop):

while($row = mysql_fetch_array($cart_result)) {
$sel_item_id = $row["sel_item_id"];
$rm_product_sql = "DELETE FROM products WHERE id = \"$sel_item_id\"";
mysql_query($rm_prodcut_sql) or die("Couldn't delete products.");
}

    1. if products.id is an integer , no double quotation is needed.
    2. there is no comparison statement. How can you know that the $sel_item_id is the one you want to delete? or you want to delete all of them?
    3. is there any error msg return?

      Maybe SELECT all the sel_item_id's into an array first? Then you can either DELETE each one with a separate query in a foreach loop or bundle them all together into one big WHILE condition and DELETE them all in one hit.

        When something is placed in the cart, flag it (IE incart = true (add the 'incart' field to the item table), when the transaction is completed, delete the flagged items.

        Fitz

          i am having problems getting to DELETE the items from the array. what am i doing wrong? below is the test code i've been using with a test mysql database in which i want to delete all the data. i am inserting the id's into the database and then telling it to delete where id = the array. is this incorrect. please help. thanks

          $sql = "SELECT * FROM test";
          $sql_result = mysql_query($sql,$connection) or die ("couldn't execute query");
          
          $i = 0;
          while ($row = mysql_fetch_array($sql_result)) {
                      $id = $row[id];
          			$delete[$i] = $id;
          			$i++;
          			}
          
          $rm_item_sql = "DELETE FROM test WHERE id = \"$delete\"";
          mysql_query($rm_item_sql) or die("Couldn't delete items.");
            Write a Reply...