Jump to content

Need Help Displaying Wrong Answers


MjM8082

Recommended Posts

Right now my application only displays the answers and problems when the user hits the score button. But when the user hits the score button I want my application to only display the problems that the user got wrong in the test. Here is my code for this applicaiton.. it is small and simple, just not sure how to do this?

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lab 5</title>
</head>

<body>
<?php
define ('ROWS', 3);
define ('COLS', 3);
define ('MAX_NUMBER', 12);
date_default_timezone_set('America/New_York');

if (isset($_POST['btn_score']))
{
	//print_r ($_POST);
	$time1 = $_POST['ts'];
	$time1_object = new DateTime($time1);
	$now = new DateTime();
	$time_span = $now->diff($time1_object);

	$minutes = $time_span->format('%i');
	$seconds = $time_span->format('%s');
	$seconds+= $minutes * 60;

	echo "It took $seconds seconds to complete the test<hr />";



	foreach ($_POST as $problem => $answer)
	{
		if ($problem <> "btn_score" && $problem <> "ts")
		{
			//echo "$problem -- $answer <br />";
			$problem = explode('_', $problem);
			$num1 = $problem[2];
			$num2 = $problem[3];

			echo "$num1 * $num2 === $answer <br />";
		}
	}
}







?>

<h1>Lab 5</h1>

<form name="lab5" method="post" action="lab5b.php">
<?php
	$now = new DateTime();
	//echo $now->format('Y-m-d H:i:s');
	echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>";
?>
<table border="1" cellspacing="5" cellpadding="5">

<?php


	$no_of_problems = 0;
	for ($row=0; $row<ROWS; $row++)
	{
		echo "<tr>";
		for ($col=0; $col<COLS; $col++)
		{
			$num1 = mt_rand(1,MAX_NUMBER);
			$num2 = mt_rand(1,MAX_NUMBER);

			echo "<td>$num1 * $num2 </td>";
			echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>";
			$no_of_problems++;
		}
		echo "</tr>";
	}
	$colspan = 2 * COLS;
	echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>";
?>	
</table>
</form>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.