我正在開發在線測試應用程序,顯示所有的問題在一個頁面options.how我可以得到所有選擇的單選按鈕提交與問題ID的值。如何獲取在php中提交所有單選按鈕的選定值?
<?php
include_once('connect.php');
$sql="select * from testquestions where testid='126'";
$result=mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result)>0)
{
$data = array(); // create a variable to hold the information
while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false)
{
$data[] = $row; // add the row in to the results (data) array
}
//shift off the first value
array_shift($data[0]);
$merge = call_user_func_array('array_merge', $data);
$size=sizeof($merge);
$newdata=array();
$num=1;
echo "<form action='fetchquestion.php' method='post'>";
foreach ($merge as $key => $value)
{
$sql2="select qid, question,option1,option2,option3,option4 from question where qid='$value' ";
$result2=mysql_query($sql2) or die(mysql_error());
while($row2=mysql_fetch_assoc($result2))
{
$questionid=$row2['qid'];
$question=$row2['question'];
$option1=$row2['option1'];
$option2=$row2['option2'];
$option3=$row2['option3'];
$option4=$row2['option4'];
$newdata[]=$row2;
echo '<div><div class="question">';
echo "$num<h3>$question</h3>";
echo "</div>
<div class='answer'>
<ul>
<li><input type='radio' class='radioBtnClass' name='option' style='width:50px' value='1'/>$option1</li>
<li><input type='radio' class='radioBtnClass' name='option' style='width:50px' value='2'/>$option2</li>
<li><input type='radio' class='radioBtnClass' name='option' style='width:50px' value='3'/>$option3</li>
<li><input type='radio' class='radioBtnClass' name='option' style='width:50px' value='4'/>$option4</li>
<input type='hidden' name='count' value='$num' id='count'>
<input type='hidden' name='queId' value='$questionid' id='queId'>
</ul></div></div>";
$num++;
}
}
echo"<input type='submit' name='submit' value='Submit'><br>
</form>
";
if (isset($_POST['submit'])) {
$_SESSION['quiz'] = array();
// get rid of the submit element in the $_POST
unset($_POST['submit']);
// assign the values of the radio buttons to the $_SESSION['quiz'] array
$_SESSION['quiz'] = $_POST;
echo "submitted form";
}
else {
echo "Please submit the form.";
}
}
else
{
echo " no questions available for selected test";
}
?>
我該如何做到這一點? 有人可以幫忙嗎?
它是每頁一個問題?你怎麼知道該選項是爲這個問題:) – 2014-10-20 06:44:27