Jump to content

I'm trying to create a simple maths question-and-answers page


alexduff

Recommended Posts

I'm attempting to create a page with 10 random questions on it.  I've managed to generate and display the questions in a table with form fields for the answers.

 

However, I am finding great difficulty in sending the questions to a page to check the answers.  It's easy enough to send the answers, but how do I send the randomly generated data alongside it?

 

Can anyone give me any clues as to how to send local variables from one page to another?

 

Any help would be greatly appreciated!!

Link to comment
Share on other sites

Sorry, JonsJava.

 

<html>
<head>
    <title></title>
</head>

<body>
    <?php
        echo'  <table width="560" border="0" cellspacing="0" cellpadding="0">';
        $answer = array();
        //
        $question_type = array();// I know I'd have been better with a 2D array here.
        $question_s = array();
        $question_d = array();
        $question_th = array();
        $question_tm = array();
        $cntr = 0;
        $nos = 10;
        for ($i = 0; $i < $nos; $i++) { // There are 10 questions
        	$type = rand(1,1);              // Questions are SDT.  To simplify, ony posted code for Distance.
        	if ($type == 1) {
       			$question_type[$i]="distance";
        		//distance
        		do {
        			$speed = rand(10, 40);
        			do {
        				$timeh = rand(0, 3);
        				$timem = rand(0, 3);
        			} while ($timeh == 0 and $timem == 0);
        			$time = $timeh + ($timem * 0.25);
        			$a = $speed * $time;
        		} while ($a <> intval($a)); // Just ensuring that the calculated distance is an integer value
        		$answer[$i] = $a;
        		$time = "";
        		if ($timeh == 1) {
        			$time = $timeh . ' hour';
        		}
        		if ($timeh > 1) {
        			$time = $timeh . ' hours';
        		}
        		if ($timeh > 0 and $timem > 0) {
        			$time = $time . ' ';
        		}
        		if ($timem > 0) {
        			$timem = $timem * 15;
        			$time = $time . $timem . ' minutes';
        		}
        		echo '<tr><td width="480" height="20"></p><tr><td width="400" height="20"> '. 'At ' . $speed . ' mph, how far would you travel in '.$time . '?   '.'</td>'; // asking the question
        		echo '<td width="160"> <input name="b'.$i.'" type="text" id="b1" size="6" maxlength="3"> miles '.$answer[$i].'</td></tr>'; // form field for the answer
        	}
         $question_d[$i]=$distance;
        	$question_s[$i]=$speed;
        	$question_th[$i]=$timeh;
        	$question_tm[$i]=$timem;
        }
        echo' </table>';
    ?>?>
</body>
</html>

 

I'm trying to find a way of telling the user how many questions they got correct out of 10, and display the original questions and answers.

 

Again, many thanks for any help anyone can give. :)

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.