Forum Home
Press F1
 
Thread ID: 85884 2007-12-25 21:37:00 Countdown timer for webpage (php) Mike (15) Press F1
Post ID Timestamp Content User
624549 2007-12-25 21:37:00 I want to add a countdown timer sort of thing to a webpage using PHP (or something else if PHP won't do it, but the rest of the site is already in PHP).

However its not a timer to a one-off set date/time event - its an event that occurs 2 or 3 times a day, eg 4:10am and 1:10pm, almost every day (one day a week it doesn't happen sorta thing)

Is it possible? How do I do it? :) I'm sure there are sites out there that have some sample code I could butcher to do mostly what I want, but I haven't been able to find anything.

Even if it just did the first part, ignoring the days it doesn't occur, that would be a start.

Mike.
Mike (15)
624550 2007-12-26 22:49:00 What starts the timer going?
Is the timer length the same time or is it variable?
What happens when the time is up?

I had NZ time on my web site every minute it would record a visitor at the web site page, some joker overseas found it and stayed at that same page for hours on end making the “recorded visit” very long for that person and useless to anyone else that came during that time, at the end of that. I just came to the conclusion “you can not have or do anything that is different because someone is going to come along and abuse it” so I had to write some code (in PHP) to stop the clock working (or been shown) after a few minutes if someone just sat at that “NZ time” web page hoping that person would move on.

PHP is not all that hard if you have done C or C++, just get out the PHP book, my one is getting a bit old.
nrrrta (11415)
624551 2007-12-26 22:58:00 What starts the timer going?
Is the timer length the same time or is it variable?
What happens when the time is up?
The timer just goes - nothing to start and stop it...
I'm thinking about an event at 4:10am and 1:10pm every day, so whatever time someone comes on it tells them how long until the next event. Sometimes there are events on only 1 or 2 days a week, so countdown to those events.

When the time is up it will just start going for the next event time.

It doesn't necessarily need to be constantly updating - something that only updates on a refresh would be fine (so it'd say 2 hours until event for however long the viewer is on that page without refreshing it - even if its longer than 2 hours lol)

I've written something pretty basic - a whole lot of if/elseif statements looking at what time it is and when the next event is (ie if time is 2am then 2 hours 10 minutes until next event). It seems to work, but I was hoping (expecting) there would be something out there that does this all a bit smarter already... I haven't been able to find anything yet :)

Mike.
Mike (15)
624552 2007-12-26 23:14:00 I see so it says "56 minutes to the 1:10pm event."

[edit note] I just had to edit it
nrrrta (11415)
624553 2007-12-26 23:26:00 I see so it says "56 minutes to the 1:10pm event."

[edit note] I just had to edit itYes

Mike.
Mike (15)
624554 2007-12-27 00:00:00 This reminds me of a few years ago I went to the dentist and had to have a tooth taken out, he could not take it out on the day, but he gave me three lots of tablets to take in the mean time, to make matters worse I had to take them at three different time intervals, I had to make up a chart what time to have them, (and of coarse if you think I am wake up in the middle of the night to take a pill, I have news for you)

It would be good if there was a portable multiple alarm timer that did the above, giving the color & name of the tablet, of coarse now the tooth is out I would have to think of a new use, like beep when it gets to 6pm so I dont miss the TV news,

I might add to my Java project, I was thinking of getting ready to sit the SUN Java "SCJP" exam next year, and thought of a "time" project would interesting.
nrrrta (11415)
624555 2007-12-27 20:39:00 It's hard to think of an app or script that'll do what you want Mike. But take a look at Webcalendar (www.k5n.us) - it may have the feature you're looking for. Greg (193)
624556 2007-12-28 01:42:00 Sounds simple enough but...

There's more information needed.

How would you like it presented to your visitors and notify them of the event? Is this just going to sit somewhere on your page, counting down? Are we going to let off fireworks on your site when this event takes place and definitely grab their attention and possibly annoy them? (actually scratch that last idea)

You would need to use a combination of languages, since you want PHP that would do, and you'll also need Javascript, that's probably all you really would need, could make use of a database to store the event days etc, or just store them in PHP but if it's going to happen quite a lot, put it in a database.

We would use PHP to set the locale time, the event time/day and javascript to do the countdown, instant page update without refreshing and let us know how long to go, updating in intervals of your choice, but I say every 5minutes?

Now the only problem is, the accuracy of the time would be close, but not exact because you'd be working with the time you grabbed at that moment, so give or take a few seconds out when the script finishes processing.

I guess you'll need examples, if I have time I'll throw some things up but hopefully this gives you the approach I would have taken to getting this going.

Cheers,

KK
Kame (312)
1