我正在创建一个多项选择测验,我每页只会显示1个问题,答案选项会随机显示给用户。
<?php
$con = mysqli_connect("localhost","root","","labquiz");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$res = mysql_query("SELECT multiplechoiceid, question, choice1, choice2, choice3, answer, description FROM multiple_choice");
$ans_array = array('choice1', 'choice2', 'choice3', 'answer');
shuffle($ans_array);
while($row = mysql_fetch_array($res)){
echo $row["multiplechoiceid"]. ".". $row["question"];
echo "<br>";
echo '<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="$ans_array[0]" required> <?=$ans_array[0]?>';
echo "<br>";
echo '<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[1]?>"> <?=$ans_array[1]?>';
echo "<br>";
echo '<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[2]?>"> <?=$ans_array[2]?>';
echo "<br>";
echo '<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[3]?>"> <?=$ans_array[3]?>';
echo "<br>";
}
?>
echo表达式中的php标签不显示答案选项,但仅显示单选按钮。
答案 0 :(得分:0)
为什么不分开你的php&amp; HTML代码&amp;像这样写 -
while($row = mysql_fetch_array($res)){
echo $row["multiplechoiceid"]. ".". $row["question"]; ?>
<br>
<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="$ans_array[0]" required> <?=$ans_array[0]?>
<br>
<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[1]?>"> <?=$ans_array[1]?>
<br>
<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[2]?>"> <?=$ans_array[2]?>
<br>
<input type="radio" name="quizid<?=$row->multiplechoiceid?>" value="<?=$ans_array[3]?>"> <?=$ans_array[3]?>
<br>
<?php } ?>
如果仍然遇到问题,请检查php.ini文件中的短代码