尝试这样的事情,你需要相应地改变它,
你的控制器:
$limit = 20;
/*pagination start*/
$this->load->library('pagination');
$config['base_url'] = base_url().'controller_name/this_function_name/';
$config['total_rows'] = $this->your_model->total_count_books();
$config['per_page'] = 30;
$config['uri_segment'] = 3;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['cur_tag_open'] = '<span class="active_page">';
$config['cur_tag_close'] = '</span>';
$this->pagination->initialize($config);
$data = array();
$data['books'] = $this->your_model->get_books($limit, $this->uri->segment( 3 ));
您的模型功能:
function total_count_books(){
$sql = "SELECT count( books.isbn ) as total FROM books
LEFT JOIN bookauthor
ON books.isbn = bookauthor.isbn
LEFT JOIN author
ON bookauthor.aid = author.id
LEFT JOIN bookscategory
ON books.bookcategory = bookscategory.id
WHERE books.stock > 0 GROUP BY books.isbn";
$data = $this->db->query( $sql )->row_array();
return $data['total'];
}
function get_books( $limit, $offset = 0 ){
$sql = "SELECT books.isbn,
books.title,
GROUP_CONCAT(CONCAT(author.fname,' ',author.lname)) AS FullName,
books.date_published,
books.price,
books.stock,
books.img,
books.summary,
books.status,
bookscategory.id AS bookcategoryid,
bookscategory.bookcategory FROM books
LEFT JOIN bookauthor
ON books.isbn = bookauthor.isbn
LEFT JOIN author
ON bookauthor.aid = author.id
LEFT JOIN bookscategory
ON books.bookcategory = bookscategory.id
WHERE books.stock > 0 GROUP BY books.isbn";
if( !$offset ){
$offset = 0;
}
$sql .= " Limit {$offset}, {$limit}";
return $data = $this->db->query( $sql )->result_array(); #or ->result();
}