是否可以像这样检查多个单选按钮?

我从我的数据库中回显单选按钮的值,并且以这种形式(while 循环)是获取它们的最快方法。当我这样做时,它会看到所有单选按钮都在同一个“组”中。如何使它具有多个“组”以便可以回答多个问题?


我尝试向它添加一个 div ,但没有奏效。


<form action="Antwoord.php" method="POST">

<?php

   $sql = "SELECT * FROM  questionlist_choice";

   $result = mysqli_query($conn, $sql);

  if ($result->num_rows > 0) {

  while ($row = mysqli_fetch_assoc($result)) {

$vraag = $row['Vraag'];

$vraagA = $row['Vraag_keuzeA'];

$vraagB = $row['Vraag_keuzeB'];

$vraagC = $row['Vraag_keuzeC'];

$vraagD = $row['Vraag_keuzeD'];

$vraagE = $row['Vraag_keuzeE'];

$vraagF = $row['Vraag_keuzeF'];

echo "<div>";

    echo "<br><p>$vraag</p>";

    echo "<input type='radio' name='gender' value='$vraagA'> $vraagA<br>";

    echo "<input type='radio' name='gender' value='$vraagB'> $vraagB<br>";

    echo "<input type='radio' name='gender' value='$vraagC'> $vraagC<br>";

    echo "<input type='radio' name='gender' value='$vraagD'> $vraagD<br>";

    echo "<input type='radio' name='gender' value='$vraagE'> $vraagE<br>";

    echo "<input type='radio' name='gender' value='$vraagF'> $vraagF<br>";

echo "</div>";




  }

}

?>

<input type="submit">

</form>


临摹微笑
浏览 100回答 1
1回答

POPMUISE

抱歉,我不太了解您的问题,但是如果您想要GROUP他们,您需要在name标签上添加索引,如下所示:$i = 0;while ($row = mysqli_fetch_assoc($result)) {&nbsp; &nbsp;$vraag = $row['Vraag'];&nbsp; &nbsp;$vraagA = $row['Vraag_keuzeA'];&nbsp; &nbsp;$vraagB = $row['Vraag_keuzeB'];&nbsp; &nbsp;$vraagC = $row['Vraag_keuzeC'];&nbsp; &nbsp;$vraagD = $row['Vraag_keuzeD'];&nbsp; &nbsp;$vraagE = $row['Vraag_keuzeE'];&nbsp; &nbsp;$vraagF = $row['Vraag_keuzeF'];&nbsp; &nbsp;echo "<div>";&nbsp; &nbsp;echo "<br><p>$vraag</p>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagA'> $vraagA<br>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagB'> $vraagB<br>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagC'> $vraagC<br>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagD'> $vraagD<br>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagE'> $vraagE<br>";&nbsp; &nbsp;echo "<input type='radio' name='gender[$i]' value='$vraagF'> $vraagF<br>";&nbsp; &nbsp;echo "</div>";$i++;}我$i用作索引,我认为如果您使用它会更好,for loop因为它已经$key有价值,我认为使用它while是一个坏习惯。
打开App,查看更多内容
随时随地看视频慕课网APP