I am trying to create a form to be used for testing during a tutorial (at the end of each module the user will be given a test).
It contains a number of questions, each with a question and 4 possible answers. The answers are radio buttons, so the user can only select 1 for each question.
I am currently selecting 5 questions randomly from a database and displaying them using a loop:
$a = 1;
while ($row = mysql_fetch_ass oc($result)){ //$result is the question data from the db
<TABLE>
<TR><TD><b><? echo "$a. ", $row ['Question']. "<br/>" ?></b></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="1"> <? print $row ['Opt_1']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="2"> <? print $row ['Opt_2']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="3"> <? print $row ['Opt_3']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="4"> <? print $row ['Opt_4']. "<br/>" ?></TD></TR>
</TABLE>
<?php
print "<br/>";
$a++;
}//end while
I have used name="Question$ a" so that each answer set will have a different name (i.e. Question1, 2,...) so i can then use $answer1 = $_POST ['Question1'] later to get the user's answer for each question. This isn't working though.
Firstly, it only allows me to select one radio button on the whole page (rather than one per question) and it is not giving each set a different name (the name="Question$ a" bit).
I have tried other options but am really struggling now. Any help will be much appreciated.
It contains a number of questions, each with a question and 4 possible answers. The answers are radio buttons, so the user can only select 1 for each question.
I am currently selecting 5 questions randomly from a database and displaying them using a loop:
$a = 1;
while ($row = mysql_fetch_ass oc($result)){ //$result is the question data from the db
<TABLE>
<TR><TD><b><? echo "$a. ", $row ['Question']. "<br/>" ?></b></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="1"> <? print $row ['Opt_1']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="2"> <? print $row ['Opt_2']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="3"> <? print $row ['Opt_3']. "<br/>" ?></TD></TR>
<TR><TD><inpu t type="radio" name="Question$ a" value="4"> <? print $row ['Opt_4']. "<br/>" ?></TD></TR>
</TABLE>
<?php
print "<br/>";
$a++;
}//end while
I have used name="Question$ a" so that each answer set will have a different name (i.e. Question1, 2,...) so i can then use $answer1 = $_POST ['Question1'] later to get the user's answer for each question. This isn't working though.
Firstly, it only allows me to select one radio button on the whole page (rather than one per question) and it is not giving each set a different name (the name="Question$ a" bit).
I have tried other options but am really struggling now. Any help will be much appreciated.
Comment