哪个是显示mysql记录的最佳分页

时间:2013-05-02 04:14:23

标签: php jquery mysql codeigniter

我有一个应用程序,其中用户获取记录以进行报告。 但是我在使用jquery分页和mysql分页(LIMIT,OFFSET)之间感到困惑。

因为jquery分页需要所有无限制的记录,所以在客户端进行分页,这可能会减慢查询速度。

mysql可以使用limit(我使用的是codeigniter框架),但每次点击分页时,它都会ping数据库以获取下一组数据,而mysql分页也会创建重复记录。

是否有一种良好而快速的分页方式,如果是,请建议我。

谢谢......

1 个答案:

答案 0 :(得分:0)

我以这种方式做了分页......

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();

}
相关问题