Jump to content

[SOLVED] deleting master records in mysql


jaminxz

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.