0
我想输入我的问卷答案到数据库选择选定复选框,并插入选中的行导入数据库
我有台这样的数据库(例如):
| id | question | answer |
+----+--------------+--------+
| 11 | have dinner? | 1 |
| 12 | have house? | 0 |
| 13 | have garden? | NULL |
| 14 | bla bla bla? | NULL |
// footnote: answer = 0 as no, answer = 1 as yes
问题如何将我的回答输入id 13,14等。到数据库
如果我的控制器:
/* I am using CodeIgniter */
$data['form_action'] = site_url('dcm/index');
$answer = $this->input->post('answer');
$id = $this->input->post('id');
$selected_answer = $answer['id'];
$this->dcm_model->inputAnswer($answer, $id); // <-- for input answer to model
我的模型:
function inputAnswer($answer, $id){
$sql = ("
UPDATE question
SET answer = '$answer'
WHERE id = '$id'
"); $this->db->query($sql);
}
鉴于:(我仍然扑朔迷离)
<?php foreach($query->result() as $row) { ?>
<span> <?php echo $row->id . '. ' . $row->question; ?> </span>
<span> <input type="checkbox" value="1" name="answer" /> </span>
<input type="submit" value="submit answer"/>
我用这个,但它不会改变我的数据库表什么...这是在控制器吗? “$这 - > dcm_model-> inputAnswer();” ?? –