Code: Select all
function options(){
$name="";
$output="";
$options["A"]="A";
$options["B"]="B";
$options["C"]="C";
$options["D"]="D";
$result=count($options);
//print "Number of elements in array: ".$result."<br>";
echo '<select class="fill_form" name="choices">';
echo '<option value=" " selected=\"Selected\">Select</option>';
foreach($options as $key => $value){
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
}Code: Select all
?>
<form id="test" name="test_form" method="post" action="ma_0030_0001_good.php">
<?php
$i=1;
while ($i<=3){
print $i.". ";
//print "<br><b>Direct variable print:</b><br>";
do{
$a = rand(2,30);
$exp1 = rand(2,10);
$exp2 = rand(2,15);
$answer1 = $exp1+$exp2;
$answer2 = $exp2*$exp1;
$answer3 = $exp1-$exp2;
$answer4 = $exp2-$exp1;
}while($answer1==$answer2||$answer1==$answer3||$answer1==$answer4||$answer2==$answer3||$answer2==$answer4||$answer3==$answer4);
$question[$i.'a']=$a;
$question[$i.'exp1']=$exp1;
$question[$i.'exp2']=$exp2;
$answer[$i.'answer1']=$answer1;
$answer[$i.'answer2']=$answer2;
$answer[$i.'answer3']=$answer3;
$answer[$i.'answer4']=$answer4;
$item=array('question'=>$question,'answer'=>$answer);
print options(); //Answer choices drop down
//prnt question
print " ".$a."<sup>".$exp1."</sup> x ".$a."<sup>".$exp2."</sup> =\n\r<br><br>";
//print answer choices
print " <b>A.</b> ".$a."<sup>".$answer[$i.'answer1']."</sup> " ;
print "<b>B.</b> ".$a."<sup>".$answer[$i.'answer2']."</sup> " ;
print "<b>C.</b> ".$a."<sup>".$answer[$i.'answer3']."</sup> " ;
print "<b>D.</b> ".$a."<sup>".$answer[$i.'answer4']."</sup><br>" ;
print "<br><br>";
$i++;
}
?>
<input type="submit" name="Submit" value="submit" />
<input type="reset" name="Reset" value="Reset" />
</form>When on ma_0030_0001_good.php I print the submitted array using print_r($_POST) I only see the last choice from the dropdown as most likely the answers owerwrite each other and only the last one is visible. How can I change the code to store the choices from the dropdown individually and how can I access them to see the answer for each question?
Thank you for your help.