为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
临摹微笑 2022-01-08 20:03:02
我从我的数据库中回显单选按钮的值,并且以这种形式(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>
查看完整描述

1 回答

?
POPMUISE

TA贡献1765条经验 获得超5个赞

抱歉,我不太了解您的问题,但是如果您想要GROUP他们,您需要在name标签上添加索引,如下所示:


$i = 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[$i]' value='$vraagA'> $vraagA<br>";

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

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

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

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

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

   echo "</div>";

$i++;

}

我$i用作索引,我认为如果您使用它会更好,for loop因为它已经$key有价值,我认为使用它while是一个坏习惯。


查看完整回答
反对 回复 2022-01-08
  • 1 回答
  • 0 关注
  • 99 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信