AV1611 Posted March 2, 2007 Share Posted March 2, 2007 I have a script that is a math speed drill for my kids (see it in action at http://blmservices.com/~osprey/school/mathdrill.php) It simply gives them 50 match problems, and when they finish it gives them a score. I now need to get the script to tell them how long they took. Basically, I need to capture the time of the first time the script loads, then mark the time when the last time the script runs, and display how long it took.... I'm lousy with doing math on time... Can someone suggest to me what time function to use? I need only to know how many minutes and seconds they took. here is the entire script if someone wants it for they're kids: <STYLE TYPE="text/css"> <!-- TD{font-family: Verdana; font-size: 20pt;} div{font-family: Verdana; font-size: 20pt;} ---> </STYLE> <div> <center> <?php if(!isset($_GET['problem'])){ $problem=1;} else {$problem=$_GET['problem'];} if($problem==51){ $correct=$_GET['correct']; if(isset($_POST['answer']) && $_POST['answer']==$_GET['answer']){ $correct=$correct+1;} $grade=($correct/50)*100; echo "<h2>Total Correct: ".$correct." Grade: ".$grade."%</h2>"; } else { if(!isset($_GET['correct'])){ $correct=0;} else {$correct=$_GET['correct'];} if(isset($_POST['answer']) && $_POST['answer']==$_GET['answer']){ $correct=$correct+1;} echo "Problem: "; echo $problem; echo " Correct: "; echo $correct; echo "<br/><br/>"; $problem=$problem+1; $top=rand(1, 99); $bottom=rand(1, 99); $answer=$top+$bottom; echo "<table>"; echo "<tr><td align='right'>"; echo $top; echo "</td></tr>"; echo "<tr><td align='right'>"; echo "+".$bottom; echo "</td></tr>"; echo "<tr><td align='right'>"; echo "<form name='sform' METHOD='POST' action='http://blmservices.com/~osprey/school/mathdrill.php?problem=$problem&correct=$correct&answer=$answer'>"; echo '<input type="text" SIZE="10" name="answer">'; echo "</td></tr>"; echo "<tr><td align='right'>"; echo "<input type='submit' name='Submit' value='Answer'>"; echo "</td></tr>"; echo "</table>"; } echo "<h2><a href=./mathdrill.php?problem=1>Start Again</a></h2>"; ?> </center></div> Quote Link to comment Share on other sites More sharing options...
danrah Posted March 2, 2007 Share Posted March 2, 2007 i think using seconds since epoch and using date() may be a good idea. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2007 Share Posted March 2, 2007 At start of test $_SESSION['startsecs'] = time(); At end of test $endsecs = time(); $timeTaken = $endsecs - $_SESSION['startsecs']; $mins = floor ($timeTaken / 60); $secs = $timeTaken % 60; printf ("You took %d mins %02d secs to complete the test", $mins, $secs); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.