【发布时间】:2020-03-29 06:21:33
【问题描述】:
我想在代码点火器中更新多个具有相同 ID 的行。只有第一个数据正在更新。我要更新多个数据
控制器
public function edit_curriculum_details($id) {
if (isset($_POST['submit'])) {
$post = $this->input->post();
$param = array(
'course_id' => $post['course_id'],
'introduction' => $post['introduction_curriculum'],
'type' => $post['type'],
'question' => $post['question_curriculum'],
'answer' => $post['answer_curriculum'],
);
$where = array('course_id' => $id);
$data['add'] = $this->Model->update_data('tbl_common', $param, $where);
}
型号 函数 update_data($table, $param, $where) {
$this->db->where($where);
$this->db->update($table, $param);
return true;
}
查看
<input class="form-control" name="question_curriculum" value="<?php echo $course['question']; ?>
数据库
+-----------+--------------+---------------------+---------+------------+-----------+
| common_id | introduction | question | answer | type | course_id |
+-----------+--------------+---------------------+---------+------------+-----------+
| 64 | curriculum | Question curriculum | answer1 | curriculum | 29 |
+-----------+--------------+---------------------+---------+------------+-----------+
| 65 | curriculun | Question curriculum | answer1 | curriculum | 29 |
+-----------+--------------+---------------------+---------+------------+-----------+
【问题讨论】:
-
update_data() 函数中有什么?为什么要在 $param 数组中添加“course_id”?
-
同时添加 Model 型号代码。
-
可能有很多课程问答。所以我需要选择否。问答然后更新。现在只获取一个第一行记录。例如。 id 64.Array ( [common_id] => 64 [介绍] => 课程 [问题] => 问题课程 How to Answer =>answer1 [类型] => 课程 [course_id] => 29)
标签: mysql codeigniter