【发布时间】:2019-06-15 20:40:35
【问题描述】:
我有一个人们可以回答问题的列表,每个问题都有三个使用单选按钮的可能答案。
在我的数据库中插入该数据可以正常工作,但现在我希望能够编辑这些列表,因此我需要从我的数据库中显示一个已填写的列表,而不是插入一个新列表。
正常数据没问题,但单选按钮有一些问题。
我的数据库结构如下:
wpi_info
-id
-other non important fields for this question
wpi_categories
- id
- title
- info_id (same as id of wpi_info)
wpi_questions
-id
-title
-answer
-cid (same as id of wpi_categories)
这是我目前显示单选按钮的方式(显示类别/问题,但未选中单选按钮):
<?PHP
$een = 1;
$twee = 2;
$drie = 3;
$getcats = 'SELECT * FROM wpi_categories WHERE info_id = "'.$conn->real_escape_string($getinfo['id']).'" ORDER BY id';
$getcatscon = $conn->query($getcats);
while($getcats = $getcatscon->fetch_assoc()){
if(!empty($getcats['title'])){
$werkplekinspectie .= '
<label class="categorytitle">'.$getcats['title'].'</label>
<div class="row">';
$getquestions = 'SELECT * from wpi_questions WHERE cid = "'.$getcats['id'].'"';
$getquestionscon = $conn->query($getquestions);
while($getquestions = $getquestionscon->fetch_assoc()){
$werkplekinspectie .= '
<div class="col-md-8">
<p class="questionclass">'.$getquestions['title'].'</p>
</div>
<div class="col-md-4">
<div class="container text-right">
<input type="radio" name="questionlist['.$getcats['title'].']['.$getquestions['title'].']" id="radio-'.$een.'" value="ok" required>
<label class="radiotoggle" for="radio-'.$een.'"><span class="radio">Ok</span></label>
<input type="radio" name="questionlist['.$getcats['title'].']['.$getquestions['title'].']" id="radio-'.$twee.'" value="fout">
<label class="radiotoggle" for="radio-'.$twee.'"><span class="radio">Fout</span></label>
<input type="radio" name="questionlist['.$getcats['title'].']['.$getquestions['title'].']" id="radio-'.$drie.'" value="nvt">
<label class="radiotoggle" for="radio-'.$drie.'"><span class="radio">N.v.t</span></label>
</div>
</div>';
$een+=3;
$twee+=3;
$drie+=3;
}
$werkplekinspectie .= '
</div>';
}
}
echo $werkplekinspectie;
?>
ok、nvt、fout 的值存储在wpi_questions 的answer 列中。
对于每个单选按钮,如果答案与我需要检查的值匹配。我该怎么做?
【问题讨论】:
-
values="whatever"> 你试过了吗?