Jump to content

Time question


AV1611

Recommended Posts

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>



Link to comment
https://forums.phpfreaks.com/topic/40901-time-question/
Share on other sites

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);

 

 

Link to comment
https://forums.phpfreaks.com/topic/40901-time-question/#findComment-198122
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.