alexduff Posted May 24, 2008 Share Posted May 24, 2008 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!! Quote Link to comment https://forums.phpfreaks.com/topic/107092-im-trying-to-create-a-simple-maths-question-and-answers-page/ Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 could you post your current code? Quote Link to comment https://forums.phpfreaks.com/topic/107092-im-trying-to-create-a-simple-maths-question-and-answers-page/#findComment-549030 Share on other sites More sharing options...
alexduff Posted May 24, 2008 Author Share Posted May 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/107092-im-trying-to-create-a-simple-maths-question-and-answers-page/#findComment-549047 Share on other sites More sharing options...
.josh Posted May 24, 2008 Share Posted May 24, 2008 you could send it as hidden fields in your form or pass it via session variables. Quote Link to comment https://forums.phpfreaks.com/topic/107092-im-trying-to-create-a-simple-maths-question-and-answers-page/#findComment-549050 Share on other sites More sharing options...
alexduff Posted May 24, 2008 Author Share Posted May 24, 2008 I saw those 'hidden fields' CV and wondered what they were - I'll play about with these. Thanks for the pointer! Alex. Quote Link to comment https://forums.phpfreaks.com/topic/107092-im-trying-to-create-a-simple-maths-question-and-answers-page/#findComment-549062 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.