'Create quiz questions for exam applications with codeigniter
Please Help me I am not getting it perfectly..actually I am fetching 60 quiz question each having four different options from database..displaying those data using pagination one at a time with 5 options..now when I switch after answering first question and go back to previous I found radio button gets unchecked.. I want it should be checked. please help me
Controller :
$data = array(
'id_aptitude' => $this->input->post('id_aptitude'),
'pilihan' => $this->input->post('pilihan'),
'a' => $this->input->post('A'),
'b' => $this->input->post('B'),
'c' => $this->input->post('C'),
'd' => $this->input->post('D'),
'e' => $this->input->post('E'),
);
$this->session->set_userdata($data);
and this is my view :
<?php $jawab_array = array(
$row->a,
$row->b,
$row->c,
$row->d,
$row->e );
?>
<?php $checked_value = $this->session->set_userdata('data'); ?>
<input type="hidden" name="id_aptitude" value=<?= $row->id_aptitude ?>>
<address>
<strong>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="pilihan<?= $row->id_aptitude?>" value="A"<?=($checked_value == 'A') ? 'checked="checked"' :''; ?> /> A
</label>
</strong>
</address>
<address>
<strong>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="pilihan<?= $row->id_aptitude?>" value="B" <?=($checked_value == 1) ? 'checked="checked"' :'' ?> /> B
</label>
</strong>
</address>
<address>
<strong>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="pilihan<?= $row->id_aptitude?>" value="C" <?=($checked_value == 2) ? 'checked="checked"' :'' ?> /> C
</label>
</strong>
</address>
<address>
<strong>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="pilihan<?= $row->id_aptitude?>" value="D" <?=($checked_value == 3) ? 'checked="checked"' :'' ?>> D
</label>
</strong>
</address>
<address>
<strong>
<label class="form-check-label">
<input type="radio" class="form-check-input" name="pilihan<?= $row->id_aptitude?>" value="E" <?=($checked_value == 4) ? 'checked="checked"' :'' ?>> E
</label>
</strong>
</address>
Solution 1:[1]
I think you can do it in 2 ways:
- Prevent your user from going back because that's how it should be. Once you answer, you can never go back. Or
- Each time the user answers, insert that answer into a database so that every time the user goes back to the previous question, you can pull out the answer from the database and display what they answered.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
