控制器:
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