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 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to set timer start with zero

    hi,

    How to set timer with start and end time?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Is this a PHP or Javascript question?

    You'll have to provide more information about your needs,
    and also what the purpose of the timer will be.

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I am trying to build a clock in PHP that counts down start from 0:00:00 to 0:30:00, resets itself and starts over again.

    Any idea how I can get that to work?

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    I just had to do the same thing!

    do you need an event to happen at the end of 30mins or do you simply just need the time to be displayed?

    if you only need the time to be displayed then it is a job for javascript which unforenetly I can not help you with.

    If you need an event to take place at then end of the minutes you can use a cronjob. All you do is write the script you want to happen every 30mins, & then set it up as a cron jon in you CPANEL crontab section.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    It will have to be a combination of PHP and Javascripting because PHP is a
    server-side scripting language. If all it has to do is count down, then reset,
    you only need Javascripting. If the countdown to zero triggers an event, you
    would have Javascripting run a PHP script when it reaches zero.

    Take your pick of Javascript timers:
    http://www.google.com/search?hl=en&q...=Google+Search

  • #6
    New Coder
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    I am doing online examination site using PHP

    If the user enter into the site and start to write the exam, I need to display the clock with start time as 00:00:00 and calculate the end time as 00:30:00 After the end time the test page will be redirected to the result page.

    This is my requirement. Can anyone help me.

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    Does your web host use cPanel as the interface and do they allow you to use cronJobs with your current plan? If you are not sure about these questions contact your host.

    If the answer to these was yes I'll explain how to set up the php.

    either scenario the javascript willl be the same so check out the link mlseim sent.

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    This is the closest thing I could find.

    It times-out and redirects to another page.

    http://javascript.internet.com/page-...-time-out.html

    EDIT:
    You didn't mention if they answer each question one at a time and the
    page refreshes or not ... refreshing would reset the timer.
    Or, do they stay on the page and click radio buttons without refreshing?
    You'll need to use PHP session variables to keep track of time if they
    refresh the page.

    With that script above, and using PHP sessions, you could have a deal where
    each question is automatically displayed when the timer reaches zero. If they
    didn't answer it, too bad ... it would just jump to the next question.
    If they answer it, you could log the time taken and then go to the next question.
    It would allow you to see how long it takes the user to answer.

    As you can see ... your project could get more complex, and more interesting.

    .
    Last edited by mlseim; 01-10-2008 at 03:09 PM.

  • #9
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Yes. My page refreshes while writing the exam.i go through the link and applied it in my application. It works but it reset the timer as you said. Is there any other idea for my requirement. I dont have any idea regarding this. If my page do not refresh means, your script is good. I dont know how to write the exam without refreshing the pages.

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Here's my thought ... but I didn't have time to make any code examples (sorry).

    The timer starts on the first page.
    Using Javascripting, it starts counting down.
    If they exit the page, either with a "submit" button, or browser button,
    the current time gets saved in a cookie.

    When you go to the next page, you read the cookie (using Javascripting)
    and continue counting.

    .... and so on ....

    each page uses Javascripting to save the time in a cookie before displaying
    the next page.

    So you need this script on each page:
    http://javascript.internet.com/page-...-time-out.html

    Then you'll need to check for the submit button to save the cookie.
    I don't have an example of that part.

    http://www.google.com/search?hl=en&q...=Google+Search

    ===========================

    Sorry I can't be of more help ... I'm just too swamped today.
    Maybe you can describe what I mentioned on the Javascript forum
    and someone (a Javascript expert) might be able to provide a nice example.

  • #11
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could also save the time they started in a php session that will be available on any refreshed pages, and calculate how much time they have left based on the current time (30 mins - (cur time - start time)). If you want the clock to actively count down while they are viewing the page, you can have php output the time they have left as part of a countdown script.

  • #12
    New Coder
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, i post my enquires in javascript forum and let u know.


  •  

    Posting Permissions

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