首页 > 解决方案 > 无法使用带有 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));

}

标签: phpajaxcodeigniter

解决方案


根据CodeIgniter 文档,我建议更改定义“where”部分的代码:

 $this->user_model->update( array('book_id' => $this->input->post('book_id')), $data);

推荐阅读