如果您有 abcd 答案或 ab 答案,如何使用此代码使其仅回显收音机或复选框。在我的测验中,它会是 abcd 和 a (true) b (false) 答案。要完成我的测验,这是唯一阻止我完成它的事情。我的问题可能不是重点,但我试图让它接近我所做的事情。谢谢你的帮助。
<?php
//retreive questions from database and put into question box
$query2 = "SELECT `QuestionId`, `Question`, `Opt1`, `Opt2`, `Opt3`, `Opt4`,`Answer` FROM `pf_questions`";
$question2 = mysql_query($query2);
while($row = mysql_fetch_array($question2)){
$id = $row['QuestionId'];
$question = $row['Question'];
$opt1 = $row['Opt1'];
$opt2 = $row['Opt2'];
$opt3 = $row['Opt3'];
$opt4 = $row['Opt4'];
$answer = $row["Answer"];
?>
<div id="ContainerQuestion">
<span class="Question">Question <?php echo $id; ?>. <?php echo $question; ?></span>
<p><input type=radio name='q<?php echo $id; ?>' <?=( $answer == 'a')?("checked='checked'"):(""); ?> value="a"> <?php echo $opt1; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' <?=( $answer == 'b')?("checked='checked'"):(""); ?> value="b"> <?php echo $opt2; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' <?=( $answer == 'c')?("checked='checked'"):(""); ?> value="c"> <?php echo $opt3; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' <?=( $answer == 'd')?("checked='checked'"):(""); ?> value="d"> <?php echo $opt4; ?> </p>
</div>
<?php
}
?>