Page 1 of 1

~ Help with arrays and sessions? ~

Posted: Sat Feb 16, 2008 5:06 pm
by Ryanc
Hi,
I need some help with a script to do multiple choice questions

I started with a script for a simple series of questions which worked that if you got the question wrong then you had to go back to the beginning and start again

I then wanted to choose the questions at random from the selection using arrays so that the questions then come up in a different order each time.
This is the script here.

I have removed the array for the minute so that the script works

Here is the question page:

Code: Select all

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <title>Quiz</title>
 
</head>
 
<body>
 
<h1>Q<?php 
$question = $_POST['question'];
echo $question; ?>
 
 
</h1><br><b>What is the name of the gland below the adrenal glands?</b><br><br>
<form method="post" action="answer.php">
<input type="radio" name="answer" value="1" />Thyroid<br>
<input type="radio" name="answer" value="2" />pituitary<br>
<input type="radio" name="answer" value="3" />pancreas<br>
<input type="radio" name="answer" value="4" />ovary<br>
<input type="radio" name="answer" value="5" />testis<br>
<input type="hidden" name="correct" value="3" />
<input type="hidden" name="question" value="
 
<?php echo $question; ?>" />
<input type="Submit" name="submit" value="Submit" />
</form>
 
 
 
 
</body>
</html>
 
 
Here is the page which processes the values sent from the question page ...

Code: Select all

 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Quiz</title>
</head>
 
<body>
 
 
<?php 
$answer = $_POST['answer'];
$correct = $_POST['correct'];
$question = $_POST['question'];
 
 
 
$questions = 28; //number of questions
 
$nextq = rand(1,$questions);
 
$nextqn = $question + 1;
 
$newarray = array_splice($arr, array_search($nextq, $arr), 1);
 
if($answer == $correct) echo "<font color=green>CORRECT</font><br><form action=bq" . $nextq . ".php method=post>
<input type=hidden name=question value=" . $nextqn . ">
<input type=submit name=Next value='Next Question'></form>";
else echo "INCORRECT<br><a href=index.php>Try again ...</a>";
 
 
 
?>
 
</body>
</html>
 

see it posted at my site
http://www.zimph.com/edu


The next stage is where I am stuck. I want to not repeat the same question ie to take it the question out of the array so that it only comes
up once in any sequence of questions. The idea is that it becomes a game to see how many questions you get right before you get the question wrong
a bit like the impossible quiz if you know that. Someone from another forum gave me this script which takes the question out of the array but this is all on one page
whereas I use mutiple pages. I am not clear how to integrate the two scripts to get what I want. Can you give me any direction on what to do next.