【发布时间】:2018-02-04 17:54:30
【问题描述】:
此代码从 db 输出不同的问题,直到 while 循环使用无线电类型的 MCQ 选项到期:
$sql = "SELECT * FROM questions WHERE `type` IN
('".implode("','",$fin_element)."')";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br>";
echo "Q:" . $row["question_name"]. "<br>";
echo "<input type='radio' name='question1' value='answer1.1'/ >
<code>".$row["answer1"]."</code>". "<br>";
echo "<input type='radio' name='question1' value='answer1.2'/>
<code>".$row["answer2"]."</code>". "<br>";
echo "<input type='radio' name='question1' value='answer1.3'/>
<code>".$row["answer3"]."</code>". "<br>";
echo "<input type='radio' name='question1' value='answer1.4'/>
<code>".$row["answer4"]."</code>". "<br>";
}
} else {
echo "0 results";
}
但这里每个问题的每个选项都具有相同的 name 属性 question1,但我希望下一个问题的 name 属性应该更改为 question2 等等。请帮忙
【问题讨论】:
标签: php html variables name-attribute