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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown Timer Help

    Hi all,
    I'm working on a text based browser game. I did a countdown timer with php and mysql. It works fine
    but you need to refresh the page to see updated timer. It's not moving like a regular timer.
    (Actually not moving at all. )

    After doing some research, I learned that I need to make countdown timer with javascript
    but I literally know nothing about it.

    Before asking any help, I want to explain how my php/mysql countdown timer works.

    When user clicks on "Start" button, my php code gets the current time:
    $now = time();
    and adds 2 hours on $now:
    $JobEnd = ($now + 7200);
    then sends $JobEnd to mysql database.

    When user checks the "Jobs" page, my php code echo's [$JobEnd from mysql database - time()].
    I also did a code to convert seconds to minutes and hours to make it look like a regular timer
    but as I said it's not moving at all unless you refresh the page.

    I need help avıyt making a javascript timer that does same thing with my php code on Jobs page
    but moves like a normal timer. Can anyone explain to me how to do that?

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Will jobEnd always be 7200 seconds after the job starts?

    If not, it would be a good idea to pass the number of seconds from PHP to JavaScript.

    Do you want the countdown timer to show the time remaining or to show the current time along with the jobEnd time and let them figure out time remaining for themselves?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Will jobEnd always be 7200 seconds after the job starts?
    No. When job starts, timer will start to count down from 7200 seconds until 0.

    Quote Originally Posted by Old Pedant View Post
    Do you want the countdown timer to show the time remaining or to show the current time along with the jobEnd time and let them figure out time remaining for themselves?
    I want the countdown timer to show the time remaining.

    _________________________________________

    To sum up,
    User clicks on "Start".
    Start button posts $JobEnd (Current Time+7200 seconds) to MYSQL database.
    When user checks the jobs list, php code echo's difference of $JobEnd from MYSQL database and Current Time as timer.
    When $JobEnd <= Current Time, timer stops and shows the result of job.

    As I said, I did all this process with php and mysql. It works fine but my countdown timer is not moving/ticking. PHP dont have function to refresh timer every 1000 milliseconds.

  • #4
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Will jobEnd always be 7200 seconds after the job starts?
    Oh sorry, I get the question work at my first replay.

    Yes again. Target time will not change. It will be stored in database as (Time Clicked on Start Button + 7200).


  •  

    Posting Permissions

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