I'm trying to making online quiz with codeigniter where there is a dynamic quiz with some subject. User can add the question and the multiple choice answer in each question. How can i get the value of each answer in each multiple choice answer on every question?
<?php echo form_open_multipart('c_kuis/addKuisAnswer'); ?>
<?php foreach($soalKuis as $row){?>
<?php $jawab_array = array($row->pil_a,$row->pil_b,$row->pil_c,$row->pil_d);
?>
<p><?=$row->soal?></p>
<input type="radio" name="jawaban<?=$row->id_soal?>" value="A">A.<?=$jawab_array[0]?></input><br>
<input type="radio" name="jawaban<?=$row->id_soal?>" value="B">B.<?=$jawab_array[1]?></input><br>
<input type="radio" name="jawaban<?=$row->id_soal?>" value="C">C.<?=$jawab_array[2]?></input><br>
<input type="radio" name="jawaban<?=$row->id_soal?>" value="D">D.<?=$jawab_array[3]?></input><br>
<input type="hidden" name="id_soal_kuis" value="<?=$row->id_soal?>"></input>
<br><br>
<?php } ?>
<button class="btn btn-primary" type="submit">Submit</button>
<?php form_close(); ?>
and this is the code looks like when i try to inspect :
<input type="radio" name="jawaban1" value="A">A.Hamster</input><br>
<input type="radio" name="jawaban1" value="B">B.Tiger</input><br>
<input type="radio" name="jawaban1" value="C">C.Shark</input><br>
<input type="radio" name="jawaban1" value="D">D.Lion</input><br>
<br><br>
<input type="radio" name="jawaban2" value="A">A.was</input><br>
<input type="radio" name="jawaban2" value="B">B.have</input><br>
<input type="radio" name="jawaban2" value="C">C.am</input><br>
<input type="radio" name="jawaban2" value="D">D.is</input><br>
<br><br>
<button class="btn btn-primary" type="submit">Submit</button>
Here is my Controller looks like :
public function addKuisAnswer(){
if($this->session->userdata('data_user')->level != 1){
redirect('/c_user/login');
}
$id_soal_kuis = $_POST['id_soal_kuis'];
$id_user = $this->session->userdata('data_user')->id_user;
$answer = $_POST['jawaban']; //The Problem's here... I should put jawaban with id_soal. Because the answer named 'jawaban1','jawaban2' etc it will follow the id_soal. How can i insert it?
$this->load->model('m_kuis');
$this->m_kuis->createAnswerKuis($id_soal_kuis, $id_user, $answer);
echo " <script>
alert('Jawaban Tugas Tersimpan!');
history.go(-2);
</script>";
}
Here is my model :
public function createAnswerKuis($id_soal_kuis, $id_user, $answer){
$data = array(
'id_soal_kuis'=>$id_soal_kuis,
'id_user' => $id_user,
'jawaban_kuis' => $answer
);
$this->db->set('tgl_jawab', 'NOW()', FALSE);
$this->db->insert('jawab_kuis', $data);
}
I want the table looks like this :This is the picture of database table i made.I want to insert the data like this.
The problem is in Controller. How can my Controller post the value of radio button name="jawaban<?=$row->id_soal?>"
in database?