...

View Full Version : Best way to do a countdown?



Remix919
05-26-2011, 04:37 PM
Hey there, I was wondering what is the best way to do a countdown script? I am trying to create a script where it will countdown to a specific time, and then once it hits 0, would change a value in the database. I figure I'll have to use a cronjob to run the script, but I would need the script to be able to manage different countdowns. Like, one countdown might change the value every hour, another might change the value every day, etc...I'd be grateful if someone could point me in the right direction as to which php functions to use for this type of task. Thanks!

Meltdown
05-26-2011, 04:42 PM
Why not just create multiple cronjobs?

Remix919
05-26-2011, 05:10 PM
Why not just create multiple cronjobs?

I could, but then I would have to manually change the cronjob each time I needed a change, and if I were to run like 10 countdowns at different times, I would need 10 cronjobs. I'd rather set 1 cronjob to run a PHP file that checks all the countdowns.

TheMachineWare
05-26-2011, 05:14 PM
Why not store a value for the time the last time the value was updated. Run a cronjob and then compare the current time to this previous time. If it is equal or greater than the last stored time, then update your value. You can then use this one time to help with your other values you want to update at different times. Everytime a value is updated, update the time for that value. You could then run the cron job once an hour and have it update multiple values at different times. Based upon the time intervals, you decide which value to update.

Remix919
05-26-2011, 06:15 PM
Why not store a value for the time the last time the value was updated. Run a cronjob and then compare the current time to this previous time. If it is equal or greater than the last stored time, then update your value. You can then use this one time to help with your other values you want to update at different times. Everytime a value is updated, update the time for that value. You could then run the cron job once an hour and have it update multiple values at different times. Based upon the time intervals, you decide which value to update.

That could work, and I guess I can just use a javascript countdown timer that pulls the last updated from the DB. Any other ideas?

Inigoesdr
05-26-2011, 07:09 PM
Create your countdowns in a database. You don't even need to create an actual counting method as you can do that on the fly when you display how much time is left until the end. You don't have to even have a cronjob unless you want to perform some action immediately when the countdown ends. Instead you can check the database to see if the countdown expired and act accordingly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum