我有一个应用程序,用户获取报告的目的记录。但我对使用jquery分页和mysql分页(限制、偏移)感到困惑。
因为jquery分页需要没有限制的所有记录,所以分页发生在客户端,这可能会减慢查询速度。
mysql可以使用limit (我使用的是codeigniter框架),但每次我点击分页时,它都会ping数据库以获取下一组数据,而且mysql分页也会创建重复的记录。
是否有好的和快速的方法来分页,如果有,请给我建议。
谢谢......
发布于 2013-05-02 13:07:54
我用这种方式做了分页......
public function page($category_id)
{
$result = $this->model_file->model_function($category_id);
$start_index = 0;
$total_rows = count($result);
$items_per_page = 10;
$filtered = array_splice($result,$start_index,$items_per_page);
$model['data'] = $filtered;
$model['page_link'] = create_page_links (base_url()."/controller_file_name/page", $items_per_page, $total_rows);
$this->load->view('view_file_name_path',$model);
}
function create_page_links($base_url, $per_page, $total_rows) {
$CI = & get_instance();
$CI->load->library('pagination');
$config['base_url'] = $base_url;
$config['total_rows'] = $total_rows;
$config['per_page'] = $per_page;
$CI->pagination->initialize($config);
return $CI->pagination->create_links();
}https://stackoverflow.com/questions/16330226
复制相似问题