[eluser]omar_yoi[/eluser]
Hi Guys,
So here is my problem:
below is my html.
-first column, to set how many questions
-2nd and 3rd, will be the question and the answer.
-user will be able to set max 3 questions and answers.
Code:
<?php echo form_open('testing/test');?>
<table>
<tr>
<td>Jumlah Pertanyaan </td>
<td><input type="text" name="jml" /></td>
</tr>
<tr>
<td>Pertanyaan 1</td>
<td><input type="text" name="pertanyaan[]" /></td>
</tr>
<tr>
<td>Jawaban 1</td>
<td><input type="text" name="jawaban[]" /></td>
</tr>
<tr>
<td>Pertanyaan 2</td>
<td><input type="text" name="pertanyaan[]" /></td>
</tr>
<tr>
<td>Jawaban 2</td>
<td><input type="text" name="jawaban[]" /></td>
</tr>
<tr>
<td>Pertanyaan 3</td>
<td><input type="text" name="pertanyaan[]" /></td>
</tr>
<tr>
<td>Jawaban 3</td>
<td><input type="text" name="jawaban[]" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Simpan" name="submit" /></td>
</tr>
</table>
<?php echo form_close();?>
Next, I would like to store this information on the database.
I have 5 columns on the table test: num, pertanyaan, jawaban, status, id.
the columns status, id will have the same values the only different will be num, pertanyaan and jawaban.
Code:
example
num pertanyaan jawaban status id
1 what is your name? Maulana ok 1
2 what is your id? maulana23 ok 1
now below is my model.
Code:
private $tbl = 'test';
$jml = $this->input->post('jml');
$questions = $this->input->post('pertanyaan');
$answers = $this->input->post('jawaban');
for($i=0;$i<$jml;$i++){
$question = $questions[$i];
$answer = $answers[$i];
$num = $i + 1;
$qna = array(
'num' => $num,
'pertanyaan' => $question,
'jawaban' => $answer,
'status' => $this->input->post('status'),
'id' => $this->session->userdata('id')
);
$this->db->insert($this->$tbl,$qna);
}
FYI:
num = number.
pertanyaan = question.
jawaban = answer.
Can someone give me a clue where I did wrong?
thanks in advance.