Results 1 to 8 of 8

Thread: [RESOLVED] Delete entire order record

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    49

    Resolved [RESOLVED] Delete entire order record

    Hi guys,

    Well I thought this was working for me but its not, doh

    I have a cart, and when people view it they can delete a product out of the cart.... I am trying to do a statement so that if they have removed all the products then the order record gets deleted.

    I have two tables:

    1) orders - one record for the entire order containing the customerid_fk and an orderid, plus total price etc
    2) orderitem - containing productid_fk, orderid_fk and quantity etc

    Here is the code I have to remove the orders record if all the records for the sessions orderid are removed from the orderitem table.

    Now i know the row=0 needs to somehow only query the orderitem table... but not sure how.
    PHP Code:
    //previous code, which deletes orderitem from orderitem table

    // REMOVE SAME ORDERID RECORD FROM ORDER TABLE IF ORDERITEM IS EMPTY
    $sqlcartrem = ("SELECT * FROM orderitem, orders 
        WHERE orderitem.OrderID_FK =  " 
    $_SESSION['OrderID'] . "
        AND orders.OrderID = " 
    $_SESSION['OrderID']);

    //check results, if no temporary cart items show message
    $resultcartrem=@mysql_query($sqlcartrem);

    //show message if no results, else show items
    $num_rows = @mysql_num_rows($resultcartrem);
    if (
    $num_rows==0){

            
    //delete order record
            
    $sqldel = ("DELETE * FROM orders WHERE OrderID = " $orderid);
            
    //do query
            
    $resultdel=@mysql_query($sqldel);
            
                   
    //delete orderitem record - not really needed!
            
    $sqldel2 = ("DELETE * FROM orderitem WHERE OrderID_FK = " $orderid);
            
    //do query
            
    $resultdel2=@mysql_query($sqldel2);


    //code to display remaining items or message saying cart is empty 
    A bit of a mess I know o_0
    Last edited by buffy; Feb 24th, 2009 at 10:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width