日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

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

發布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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分页显示结果数和页数的全部內容,希望文章能夠幫你解決所遇到的問題。

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