Quando ricevi dei post, il nome della colonna è book_id . Quando elimini è id . Quindi forse devi cambiarlo in book_id .
Inoltre $this->uri->segment(3) in questo caso restituirà null, perché function delete() non aveva parametri Maggiori dettagli leggi qui
Ma apporterò alcune modifiche:
Titolare del trattamento:
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);
}
Modello:
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');
}