Khi bạn nhận được bài đăng, tên cột là book_id . Khi bạn xóa là id . Vì vậy, có thể bạn cần thay đổi nó thành book_id .
Ngoài ra $this->uri->segment(3) trong trường hợp này sẽ trả về null, vì function delete() không có tham số. Chi tiết khác đọc tại đây
Nhưng tôi sẽ thực hiện một số thay đổi:
Bộ điều khiển:
public function delete()
{
$id=$this->uri->segment(3); // Try to write any id here, or in function put parameter
$this->book_model->deletepost($id);
$data['books']=$this->book_model->getposts();
$this->load->view('showbooks',$data);
}
Mô hình:
public function getposts() {
return $this->db->get('books')->result_array();
}
public function deletepost($id) {
$this->db->where('book_id',$id); // I change id with book_id
$this->db->delete('books');
}