コントローラ:
public function delete()
{
$id=$this->uri->segment(3);
$this->book_model->deletepost($id);
$data['books']=$this->book_model->getposts();
$this->load->view('showbooks',$data);
}
モデル:
public function getposts()
{
$posts=$this->db->get('books');
$books=array();
foreach ($posts->result() as $row)
{
$books=array(
'book_id' => $row->bookid,
'book_name' => $row->booktitle,
'book_author' => $row->bookauthor,
'book_year' => $row->bookyear,
'book_isbn' => $row->bookisbn,
'book_publisher' => $row->bookpublisher
);
}
return $books;
}
public function deletepost($id)
{
$this->db->where('id',$id);
$this->db->delete('books');
}
問題は、レコードを削除できないことです。これはエラーです:Unknown column 'id' in 'where clause'
DELETE FROM `books` WHERE `id` = 0