perky416 Posted April 13, 2011 Share Posted April 13, 2011 Hi Everyone, Im looking for a bit of advice. Im working on an auction script. Currently when an item is sent to auction, the status is set to "At auction". Is it possible that when the auctions ends that i can automatically update the database to change the status to "Auction Won" or "Auction Lost"? Or would i have to execute a query when the user opens the page displaying the data? Something like... if ($date > $end_date) { mysql_query("UPDATE auction SET status='Auction Won'"); } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233623-automatically-update-database-without-using-a-query/ Share on other sites More sharing options...
sunfighter Posted April 13, 2011 Share Posted April 13, 2011 I think there are two times you want to check and update the status. 1.) when a user views the page and 2.) when a user bids. I think this will answer the update question. Quote Link to comment https://forums.phpfreaks.com/topic/233623-automatically-update-database-without-using-a-query/#findComment-1201317 Share on other sites More sharing options...
perky416 Posted April 14, 2011 Author Share Posted April 14, 2011 Hi Sunfighter, I was thinking of adding the update query on the page that displays the status, however if me or a member of the admin are browsing the database and the staus is set to "auction running" when in fact the auction has already ended and the user has not visited the page to update the status it could be quite misleading. Is it possible to update the status automatically when the end date & time is reached? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233623-automatically-update-database-without-using-a-query/#findComment-1201743 Share on other sites More sharing options...
kickstart Posted April 15, 2011 Share Posted April 15, 2011 Hi Not really. You could set up a cron job to run every few minutes, but in this case not sure it is any better. A page displaying out of date info will be confusing however you do it. Updating the database automatically somehow will not fix the out of date page that is being looked at. Doing an update to the database when things change is effectively no different to doing the update when anyone views the data (ie, just prior to getting the data to display). If you want the data on display to reflect what is correct then you need to have the display update itself. Either using Javascript to calculate updates and update the display (ie, a count down). Or use Ajax to regularly query the database again and update the display. Personally just do the update on EVERY page refresh, whether it is to do with that auction or not. Done this way (and with decent keying) there shouldn't be many updates per page and they shouldn't take long. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/233623-automatically-update-database-without-using-a-query/#findComment-1201953 Share on other sites More sharing options...
sunfighter Posted April 15, 2011 Share Posted April 15, 2011 @ kickstart - Yes a cron job would get the job done, but at the cost of server time. I didn't mention it because I didn't know how often it should run (could be needed every second) nor how many actions are going on( meaning, how long the cron check would run) @ perky416 - What I did assume was you would check the end time of the action (contained in the DB) with the current time to determine if the auction was open or closed. If you update when anyone views the page it will be updated to the correct status. Anyone is = The Person that placed the item, You or your staff, A person just lookie lowing, Or someone coming to place a bid. They all trigger the update status and display the correct "auction running" or "auction over" That is my (1.). BUT if a bidder keeps the page open to make a last time bid - you need to check that when he bids and not accept the bid if the time comparison shows the auction closed. That's why I added a second time (2.). Quote Link to comment https://forums.phpfreaks.com/topic/233623-automatically-update-database-without-using-a-query/#findComment-1202058 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.