我正在从 MySQL 数据库中检索值,并将它们填充到单选按钮中供用户选择。这些都包含在一个 div 中,其中的问题也是动态填充的。出于某种原因,它用问题填充了所有相关的答案,但是第二到第四个答案似乎与第一个答案分开,只有第一个问题有一个中断,知道什么会导致这种情况吗?以下是生成我正在做的事情的代码:
// Connect to the Database
require_once('mysqli_connect.php');
//create the query for the question
$q = "SELECT `Question` FROM tbl_Question WHERE QuestionID = 1";
//Create the query for the Answers
$q2 = "SELECT `Answer`,`AnswerStatusID` FROM tbl_Answer WHERE QuestionID = 1";
//Run the query
$r = mysqli_query($conn,$q);
//run the answer quert
$r2 = mysqli_query($conn,$q2);
//Assign the AnswerStatusID to a var
$AnswerStatusID[] = $row2['AnswerStatusID'];
while($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){
echo '<div id="Question1"><p>1)' . $row['Question'] . '</p>';
}
while($row2 = mysqli_fetch_array($r2,MYSQLI_ASSOC)){
echo '<input name="q1" type="radio"value="'.$AnswerStatusID.'"/>' . $row2['Answer'] . '</div><br/>';
}