我正在尝试创建一个测验系统。这是我从数据库获取所有问题的表格:
<form method="POST">
<?php
$query = "SELECT * FROM quiz";
$run = mysqli_query($con,$query);
while ($rows = mysqli_fetch_assoc($run)) {
?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title"><?php echo $rows['question']?></h4><hr style="margin-bottom: -25px;">
<a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
</div>
<div class="card-content">
<div class="card-body">
<div class="custom-control custom-radio form-group">
<input type="radio" class="custom-control-input form-control" name="customRadio" id="customRadio1">
<label class="custom-control-label" for="customRadio1"><?php echo $rows['option2']?></label>
</div>
<div class="custom-control custom-radio form-group">
<input type="radio" class="custom-control-input form-control" name="customRadio" id="customRadio2">
<label class="custom-control-label" for="customRadio2"><?php echo $rows['option2']?></label>
</div>
<div class="custom-control custom-radio form-group">
<input type="radio" class="custom-control-input form-control" name="customRadio" id="customRadio3">
<label class="custom-control-label" for="customRadio3"><?php echo $rows['option3']?></label>
</div>
<div class="custom-control custom-radio form-group">
<input type="radio" class="custom-control-input form-control" name="customRadio" id="customRadio4">
<label class="custom-control-label" for="customRadio4"><?php echo $rows['option4']?></label>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
<button type="submit" class="btn btn-success">Submit</button>
</form>
仅当ID和For Attr具有相同的值时,单选按钮才起作用 对于所有问题,这应该有所不同。喜欢
第一个问题应该是:
和第二名:
答案 0 :(得分:0)
您可以将<input>
包装到<label>
中,以达到没有id的相同效果。
<div class="custom-control custom-radio form-group">
<label class="custom-control-label">
<?php echo $rows['option3']?>
<input type="radio" class="custom-control-input form-control" name="customRadio">
</label>
</div>