php - 无法使用带有 codeigniter 的 ajax 进行更新
问题描述
当我更新一列时,会更改所有列。我该如何解决?
模型
public function update($where, $data)
{
$this->db->update($this->table, $data, $where);
return $this->db->affected_rows();
}
控制器:
public function ajax_update()
{
$data = array(
'book_title' => $this->input->post('book_title'),
'book_isbn' => $this->input->post('book_isbn'),
'book_yop' => $this->input->post('book_yop'),
'book_active' => $this->input->post('book_active'),
'publisher_name' => $this->input->post('publisher_name'),
'author_name' => $this->input->post('author_name'),
);
$this->user_model->update( $this->input->post('book_id'), $data);
echo json_encode(array("status" => TRUE));
}
解决方案
根据CodeIgniter 文档,我建议更改定义“where”部分的代码:
$this->user_model->update( array('book_id' => $this->input->post('book_id')), $data);
推荐阅读
- authentication - 管理多个用户的一个帐户
- python - 在一个循环(loop)中创建一个虚拟变量
- image-segmentation - 二值图像的弹性失真
- java - 从 jar 文件创建 linux DEB 时 Jpackage 'invalid option [class]' 错误
- spring - Spring Boot - @RestController 注释被拾取,但是当用 @Controller 注释替换时,它停止工作
- python - 如果 5 列中有 3 列低于特定值,则删除行
- python - 有没有办法解决 __init__.py 的导入问题?
- opencv - Gtk-WARNING **:无法打开显示:树莓派 opencv 问题
- jupyter-notebook - 在公司网络中为我的团队部署文本分析工具有哪些选择?
- javascript - 从 JSON 中获取数据并使用 JAVASCRIPT 仅在 HTML 表中显示特定数据