首先加载分页类
$this->load->library('pagination');
然后设置分页属性
// 每页显示的数量 $config['page_size'] = 10; // 总数据量 $config['total_rows'] = 200; // 设置分页跳转页面的基础地址 $config['base_url'] = site_url('index.php/user/test'); // 设置分页显示文字 $config['first_link'] = '首页'; $config['next_link'] = '下一页'; $config['prev_link'] = '上一页'; $config['last_link'] = '末页';
初始化分页类
$this->pagination->initialize($config);
创建链接并传递给视图
$data['links'] = $this->pagination->create_links(); $this->load->view('test', $data);
通过URL获取偏移量拼装查询
$offset = (int)$this->load->uri->segment(3); $sql = "SELECT * FROM blog_user limit $offset, $page_size";