jaminxz Posted February 22, 2009 Share Posted February 22, 2009 firstly i'm new here and to php/mysql so hi guys! i'd like some help with a web app i'm building at the mo. Basically I have two tables that share a one to many relationship, kinda like an orders table and an order_item table where order item is related to orders by the Order_No PK and the PK of Order_Item is Order_No and Product no. At the mo my web app has one page that handles basic user updates, add and delete order items, but when every order_item is deleted a record still exists in the order table. I need to write some sort of logic like IF Order_No.Number of items = 0, delete the order record but I have no clue where to start. any help greatly appreciated. Jaminxz. Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/ Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 Huh? Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769060 Share on other sites More sharing options...
jaminxz Posted February 23, 2009 Author Share Posted February 23, 2009 basically, i have two tables ORDER: Order_ID, Date; and Order_Item:Order_ID, Product_ID, Quantity. I'm just building a simple prototype at the mo so i've hand typed a little bit of data myself. Currently my webb-app allows a user to add and remove order_Items from an order, but when an order has no more order_items that order should no longer exist. I would like some guidence on how to deal with this as I have no idea where to start. thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769089 Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 Why bother? Just leave it there... Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769147 Share on other sites More sharing options...
jaminxz Posted February 23, 2009 Author Share Posted February 23, 2009 isn't that bad practice? Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769214 Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 isn't that bad practice? Well, you can always find them later... depends what you're doing with them. Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769279 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 If you unconditionally delete the row from the order table when the number of items reaches zero, what happens if I add one item, decide to remove it, add a different item, then complete the order? This is a common occurrence. You will end up with a lot of deleted rows for orders that were actually placed. How this is normally done is just leave the rows in the database and run a cron job or scheduled task to remove any entries that were never completed that are x amount of time old (~ 1 week or so.) During this process you also generate a report of incomplete orders so that you can see if there is some problem on the site that is causing a lot of incomplete orders. Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-769380 Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 Agreed... a LEFT JOIN can always find empty orders. I never throw away information. Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-770166 Share on other sites More sharing options...
jaminxz Posted February 25, 2009 Author Share Posted February 25, 2009 great, thanks for the advice - much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/146430-solved-deleting-master-records-in-mysql/#findComment-770933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.