日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

php分页显示页数代码,php-Codeigniter分页显示结果数和页数

發布時間:2023/11/27 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php分页显示页数代码,php-Codeigniter分页显示结果数和页数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在使用Codeigniter 3,并且有一個簡單的PHP應用程序.

使用分頁類,我想在每個頁面的頂部顯示以下內容;

Showing x to y of z results

哪里;

x = start row

y - end row

z = total rows

`Showing 1 to 10 of 5213 results.`

`Showing 11 to 20 of 5213 results.`

`etc`

我可以使用$config [‘total_rows’]變量檢索總行.雖然不確定其余部分.

我的items.php控制器看起來像這樣;

public function index() {

$config['base_url'] = '/items/index';

$config['use_page_numbers'] = FALSE;

$config['reuse_query_string'] = TRUE;

$config['total_rows'] = $this->db->get('item')->num_rows();

$config['per_page'] = 10;

$config['num_links'] = 10;

$config['full_tag_open'] = '

  • ';

$config['full_tag_close'] = '

';

$config['first_link'] = '? First';

$config['first_tag_open'] = '

';

$config['first_tag_close'] = '

';

$config['last_link'] = 'Last ?';

$config['last_tag_open'] = '

';

$config['last_tag_close'] = '

';

$config['next_link'] = 'Next →';

$config['next_tag_open'] = '

';

$config['next_tag_close'] = '

';

$config['prev_link'] = '← Previous';

$config['prev_tag_open'] = '

';

$config['prev_tag_close'] = '

';

$config['cur_tag_open'] = '

';

$config['cur_tag_close'] = '

';

$config['num_tag_open'] = '

';

$config['num_tag_close'] = '

';

$config['anchor_class'] = 'follow_link';

$this->load->library('pagination');

$this->pagination->initialize($config);

$data = array(

'items' => $this->items_model->itemList()

);

$this->load->view('item_list', $data);

}

我的網址采用以下格式;

items/index // displays results 1-10

items/index/10 // displays results 11-20

items/index/20 // displays results 21-30

任何幫助,將不勝感激.

謝謝

解決方法:

$data['z'] = $config['total_rows'];

$data['x'] = (int)$this->uri->segment(3) + 1;

if ($this->uri->segment(3) + $config['per_page'] > $config['total_rows']) {

$data['y'] = $config['total_rows'];

} else {

$data['y'] = (int)$this->uri->segment(3) + $config['per_page'];

}

另外,如果需要的頁面在范圍內,則可以在加載視圖之前進行一次檢查;如果不是,則應根據需要將訪問者重定向到首頁或最后一頁.

標簽:codeigniter-3,codeigniter,pagination,php

來源: https://codeday.me/bug/20191111/2019335.html

總結

以上是生活随笔為你收集整理的php分页显示页数代码,php-Codeigniter分页显示结果数和页数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。