rn14 Posted February 28, 2007 Share Posted February 28, 2007 Im selling tickets and I need to be able to reduce the total number of tickets when one is sold. I have a table with the total number of tickets stored in a field and and a field with the quantity sold in a particular purchase. I think this is a fairly simple update query can anybody help get me started? Quote Link to comment https://forums.phpfreaks.com/topic/40620-update-query/ Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 That's the wrong approach -- you should never actually store the total number of tickets remaining, since it's a dynamic value. Quote Link to comment https://forums.phpfreaks.com/topic/40620-update-query/#findComment-196870 Share on other sites More sharing options...
paul2463 Posted March 1, 2007 Share Posted March 1, 2007 two of the three values has to be stored to work out the third number started with(stored) - number sold(stored) = number remaining number started with(stored) - number remaining(stored) = number sold etc etc $query = "UPDATE table SET amountsold = amountsold+1 WHERE ticketid = '$tid'"; Quote Link to comment https://forums.phpfreaks.com/topic/40620-update-query/#findComment-196880 Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 Yeah, but that's also undesirable... don't store counters! Simply have a purchases table with all of the tickets purchased, and then sum them up as necessary. Quote Link to comment https://forums.phpfreaks.com/topic/40620-update-query/#findComment-196910 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.