Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Best way to do a countdown?

    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!

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    Why not just create multiple cronjobs?
    <3 CF

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Meltdown View Post
    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.

  • #4
    New Coder
    Join Date
    Mar 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by TheMachineWare View Post
    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?

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •