View Single Post
Old 21st November 2005, 05:57 AM   #6

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default

This is how I re-wrote the code to add a scoring facility. It still works but does not score.

timestable1.php
<?php
session_start();

$n1 = rand (1, 12);
$n2 = rand (1, 12);

$_SESSION['n1'] = $n1;
$_SESSION['n2'] = $n2;
?>
<html>
<head>
<title>Times table on your Mobile</title>

<body style="margin: 0 5px; padding: 0; border: 0;text-align:center;
font-family:sans-serif;background-color:#ffffcc;">

<span style="color:red;font-size:medium;">Times Table</span>
<hr />

<?php
print "<span style='font-size:small; color:maroon;'>Multiply</span> $n1 <span style='font-size:small; color:maroon;'>by</span> $n2 <br />";
?>

<form method="get" enctype="multipart/form-data" action="http://www.dtscan.com/mobile/timestable2.php">

<span style="font-size:small; color:maroon;">

What is your answer<br />
<input type="text" name="answer" size="2" /><br />

<input type="submit" name="submit" value="Check Answer" />

<br />&nbsp;<br />
<hr />
<?php
$total = $_COOKIE['total'];
$score = $_COOKIE['score'];

if ($total == 0) {print ""; }

else {
$percent = $score/$total*100;

print "Your Score is $percent from $total Questions";
}
?>


<div style="text-align:center">
| <a href="http://www.edufacts.info/maths.html">Maths</a> |
</div>
</span>

</form>
</body>
</html>


timestable2.php
<?php

setcookie ('total',$total);
setcookie ('score',$score);


session_start();

$answer = $_GET['answer'];
$n1 = $_SESSION['n1'];
$n2 = $_SESSION['n2'];

$ans = $n1 * $n2;

if ($answer == $ans)
{
$score = $score + 1;
$total = $total + 1;


print "<hr />Correct Answer<hr /><a href='http://www.dtscan.com/mobile/timestable1.php'>Next Question</a>";
}
else
{
$total = $total + 1;
print "<hr />Wrong Answer<br />Correct answer is $ans<hr /><a href='http://www.dtscan.com/mobile/timestable1.php'>Next Question</a>";
}
?>
techitout is offline   Reply With Quote