Countdown Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Countdown Script

Post by netpants »

Hey All,

I have a browser based game , and it adds money to everyones account every half hour. So I need a script that will count down every half hour using the servers clock. So if its 11:06 in the server the counter would say "24m34s until next tick" Then after it reaches the 0m0s mark it restarts again at a half hour, but it has to be in sync with the servers clock or it just wouldn't make sense. Any help would be appreciated.

THanks
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

search this forum for 'cron' and 'windows task scheduler'.

you can set up a cron to run a php script every half hour and do whatever you'd like it to do.
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

to be hoenst that didnt help me much, I have found many countdown scripts and its no big deal to setup a cron job to run the script, but whats the code to countdown every half hour and have the cron set so that when the cron runs it refreshes the counter. I am confused on all of that.

I am trying to display the countdown in the page.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

You don't write the script to count down, you let cron do it. You'd set up a cron job to run a script every 1/2 hour, then just have that script increment the values whenever it's called.

To determine the time left until the next increment, just determine the time left until the next 1/2 hour mark.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

I am not trying to increment a value, I am just trying to display in my website, a counter that starts from 30 minutes and goes down to 0 minutes, and its synced up with the system clock, so every half hour it will start over from 30 and work its way down to 0 and so on and so forth. So if the time is 11:22 it will be displaying "8m0s Till next Tick" once it hits 11:30 it will say "30m0s Till Next Tick"
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ok, so rather than checking against the database for some value that says the last time it was updated, just get the value of time() and compare it to the next 1/2 hour increment to see what's left.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

Yes and then display what is left of the half hour on the page. But I want it to actually count and update without refreshing the page.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

OOOOOHHHHH. Ok, now I get it.

Um... use Javascript? When the page loads initialize Javascript variable & then use JS to count down. I'm not sure how you'd do that exactly. There's bound to be tons of stuff regarding Javascript timers accessible through Google.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply