LIMIT 子句可用于限制 SELECT 语句返回的行数。
现在您有 25 个结果,并且您将查询限制为返回 25 个结果,因此您的分页可能无法正常工作。
尝试在查询中传递 $config[per_page]
$this->data['products'] = $this->products_model->get_products_and_category($config['per_page'],$this->uri->segment(4));
然后在查询中(注意我们将 per_page 变量传递给 limit())
public function get_products_and_category($num, $offset=0) {
$this->db->select('products.product_id, products.product_title, products.product_created, products.parent_category, categories.category_id, categories.category_title')
->from('products')
->join('categories' , 'products.parent_category = categories.category_id', 'left')
->order_by('products.product_title', 'ASC')
->limit($num, $offset); // Here we pass the per_page var
$query = $this->db->get();
return $query->result_array();
}
希望这可以帮助