SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Countdown timers

    Have gone all over the net looking but can't seem to find a simple php code to just countdown to 4pm every Wednesday for example. All I seem to find, is for yearly events like birthdays. Can anyone help please? Pure PHP and no js.

    Many thanks.

    Dez

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Countdown how? Where? Like a clock in your browser? You can't do that with PHP. You could in theory do continuous AJAX calls (but that's JS) or autorefresh the page, but that makes little sense.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you even want counter in PHP? As guido said, it's pointless.

  4. #4
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lots of very good reasons, but this particular one, is so that there's a countdown on a website page, to 4pm every Wednesday, then, when that time is reached, it counts down again to the next Wednesday 4pm, in days, hours and minutes.

    Amy help appreciated.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Dez View Post
    Lots of very good reasons, but this particular one, is so that there's a countdown on a website page, to 4pm every Wednesday, then, when that time is reached, it counts down again to the next Wednesday 4pm, in days, hours and minutes.

    Amy help appreciated.
    That is not a good reason why you want to do it in PHP. Do it in Javascript.

  6. #6
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    It's a good enough reason for me. Anyone know how to do it in PHP ?

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    You CAN'T do it in PHP. PHP is server side. Your webpage is shown clientside.
    You can't use AJAX because it uses JS as well.
    So you might try with something like:
    Code:
    <meta http-equiv="refresh" content="5" >

  8. #8
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't use php for such thing, you use Javascript as guido mentioned already.

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    gimme a J, gimme an A, gimme a V, gimme an A, gimme an S, gimme a C, gimme an R, gimme an I, gimme a P, gimme a T !

    What do you get?
    J A V A S C R I P T

    Exactly!
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  10. #10
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dez View Post
    It's a good enough reason for me. Anyone know how to do it in PHP ?
    With a PHP timer, on page load at best all you will get is the time left to a date/time in the future but it will not continue to count down the time after the page has loaded.

    If you want the timer to continue counting down after the page has loaded then you will have to use JAVA (f'ing) SCRIPT (excuse my french ) in either plain vanilla flavour or AJAX (which would be pointless imho)

  11. #11
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks for the input, I'll rethink this a little more. I was trying to avoid js, because some people have it disabled.

  12. #12
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The question is, do you need the physical timer to actually tick down, or just display the time till wed on page load once.

    I believe everyone is assuming the former, thus you would need js to do it properly.

  13. #13
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, the former, to tick down while on the site.

    If it has to be done with js, what's the leanest way to do it please ?

  14. #14
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    With jQuery you could use a plugin like this:
    http://keith-wood.name/countdown.html

    If you don't want to use jQuery, then maybe a library like DateJS might help.

    Writing your own solution might be the leanest way to do it, but it'll require quite a bit of coding.

  15. #15
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you google something like "countdown timer javascript" you will get a truck load of hits.

    if you post your code we can try to help you get it going if you get stuck.


Bookmarks

Posting Permissions

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