#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    9
    Rep Power
    0

    javascript timer in php quiz


    i have seen many quiz system using javascipt to show user how long they take the quiz.

    i just imagine is it possible implement it in php since variable in javascript not in $, just the name, how to pass it to php script like quiz, so after they take quiz page said:

    congratulation, it's only takes 1 minute and 23 second .

    i have search in manual on how to do that using time(),
    $timestart=time();

    code ....

    $timeend=time();

    $used_time=$timestart-$timeend;
    $used_time=date('m:s',$used_time);

    but by echo $used_time it just give me strange result, even i take long time or shor time only result not far range between 01:23-01:35.

    how to track time use by user to complete quiz , is it done by php or javascript ? like http://www.ewebquiz.com/ which is written in asp.

    any hint are appreciate

    thanks,
  2. #2
  3. Newbie :P
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Jan 2001
    Location
    In the PHP Engine :-)
    Posts
    2,880
    Rep Power
    21
    Hi,

    The code you have found should work, the problem is how you implement that code into your system, simply putting it all into one page will not work because PHP is server side, so the page is called, the code is processed and the results sent back to the browser, try implementing it in the following way:

    PHP Code:
    $timestart=time(); 
    Now get the user to fill out the quiz etc and send the results to a second page, include in the form a hidden value like so

    PHP Code:
    <INPUT TYPE="HIDDEN" NAME="timestart" VALUE="<?echo $timestart;?>">
    Then in the page that checks the data of the quiz put the following code:

    PHP Code:
    $timeend=time();

    $used_time=$timestart-$timeend;
    $used_time=date('m:s',$used_time); 
    That should give you a more accurate reading.

    HTH
    ---------------------
    -- SilkySmooth --
    ---------------------
    Proxy

IMN logo majestic logo threadwatch logo seochat tools logo