我想在代码点火器中更新多个具有相同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_batch()
方法。有关如何准备数据的更多详细信息,请查看以下文档:https://codeigniter.com/user_guide/database/query_builder.html#updating-数据