...

View Full Version : how to set timer start with zero



heartlin
01-10-2008, 11:58 AM
hi,

How to set timer with start and end time?

mlseim
01-10-2008, 01:55 PM
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.

heartlin
01-10-2008, 02:10 PM
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?

srule_
01-10-2008, 02:38 PM
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.

mlseim
01-10-2008, 03:20 PM
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=javascript+timer&btnG=Google+Search

heartlin
01-10-2008, 03:22 PM
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.

srule_
01-10-2008, 03:29 PM
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.

mlseim
01-10-2008, 04:00 PM
This is the closest thing I could find.

It times-out and redirects to another page.

http://javascript.internet.com/page-details/session-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.

.

prabha
01-11-2008, 08:03 AM
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.

mlseim
01-11-2008, 06:06 PM
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-details/session-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=javascript+cookies&btnG=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.

Death_oClock
01-12-2008, 04:17 AM
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.

heartlin
01-12-2008, 11:43 AM
ok, i post my enquires in javascript forum and let u know.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum