0

我正在创建链接 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();
4

3 回答 3

0

您应该计算总页数,不要忘记添加偏移量和限制数据,还应该有模型通过限制和偏移量调用数据,因此您的 post->get per_page 值决定了下一个数据是什么。并从您的视图中加载分页。我还从我的 lang 文件中放入了第一个和最后一个值。反之亦然,有一天您可能需要更改语言。

[Codeigniter 分页][1]

totalRows,通过count listdata查找所有数据,通过limit offset offset查找所有数据,通过从per_page获取数据来决定offset在哪里获取值。

> $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 ();
于 2013-11-06T14:18:00.727 回答
0

你能试试这个:

$config['uri_segment'] = 3; replace this by $config['uri_segment'] = $this->uri->rsegment(3);
于 2013-11-07T04:23:39.703 回答
0

您需要根据在函数第三段中获得的偏移量从数据库中获取结果。这$config['uri_segment'] = 3;定义了哪个段保存偏移量。将此$this->uri->segment(3)用作您的限制条款中的偏移量$limit

于 2013-11-06T07:50:57.360 回答