我创建链接1 2 selanjutnya,但如果我点击页面'2'或'selanjutnya'数据无法更改,第1页总是10个数据...为什么?
$config['base_url'] = site_url() . 'transaksi/index/';
$config['total_rows'] = $tot_hal->num_rows();
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
echo $this->uri->total_segments();
$config['first_link'] = 'Awal';
$config['last_link'] = 'Akhir';
$config['next_link'] = 'Selanjutnya';
$config['prev_link'] = 'Sebelumnya';
$this->pagination->initialize($config);
$bc["paginator"] = $this->pagination->create_links();
答案 0 :(得分:0)
您需要根据您在函数第三段中获得的偏移量从数据库中获取结果。此$config['uri_segment'] = 3;
定义哪个段包含偏移量。在$this->uri->segment(3)
的限制条款中使用此$limit
作为偏移量。
答案 1 :(得分:0)
您应该计算总页数,不要忘记添加偏移和限制数据,您还应该有模型来通过限制和偏移调用数据,因此您的post-gt; get per_page值决定下一个数据是什么。并从您的视图加载分页。我还从我的lang文件中输入了第一个和最后一个值。反之亦然,有一天你可能需要改变语言。
[Codeigniter Pagination] [1]
totalRows,按计数查找所有数据 listdata,按限制偏移量查找所有数据 offset,通过从per_page获取数据来确定偏移的位置。
> $data ['listvalues'] = $this->some_model->listdata ($limit, $offset);
> $this->load->library ( 'pagination' ); $data ['totalRows'] =
> $this->some_model->totalRows ( ); $limit = 10; $per_page = 10; $params
> = $this->uri->uri_to_assoc (); $offset = $this->input->get ( 'per_page' ); $config = array ( 'uri_segment' => 1, 'per_page' =>
> $per_page, 'total_rows' => $data ['totalRows'], 'base_url' =>
> site_url ( 'somepage/?' ), 'page_query_string' => TRUE,
> 'full_tag_open' => '<ul>', 'full_tag_close' => '</ul>',
> 'cur_tag_open' => '<li class="active"><a>', 'cur_tag_close' =>
> '</a></li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>',
> 'next_tag_open' => '<li>', 'next_tag_close' => '</li>',
> 'num_tag_open' => '<li>', 'first_link' => lang (
> 'links_pagination_first' ), 'last_link' => lang (
> 'links_pagination_last' ), 'last_tag_open' => '<li>',
> 'last_tag_close' => '</li>', 'first_tag_open' => '<li>',
> 'first_tag_close' => '</li>', 'first_link' => lang (
> 'links_pagination_first' ), 'last_link' => lang (
> 'links_pagination_last' ), 'num_links' => '10' );
> $this->pagination->initialize ( $config );
> $data ['pagination'] = $this->pagination->create_links ();
答案 2 :(得分:0)
请你试试这个:
$config['uri_segment'] = 3; replace this by $config['uri_segment'] = $this->uri->rsegment(3);