I have a list where people can answer questions, each question has three possible answers using radio buttons.
Inserting that data in my database works fine but now I want to be able to edit those lists so I need to display an already filled in list from my database instead of inserting a new one.
Normal data is no problem but I am having some issues with the radio buttons.
My database structure looks like this:
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)
This is how I currently show the radio buttons (categories/questions show up but the radio buttons are not checked):
<?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;
?>
The values ok
, nvt
, fout
are what is stored in the answer
column of wpi_questions
.
For every radio button, if the answer matches the value I need it to be checked. How can I do that?