Super easy to use php paging class and calling method
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:52:22
Original
985 people have browsed it
-
-
/**
- * php paging code
- * edit: bbs.it-home.org
- */
- class Page {
- private $total; //Total records
- private $pagesize;//How many records are displayed per page
- private $limit; //limit
- private $page; //Current page number
- private $pagenum; //Total page number
- private $url; //Address
- private $bothnum; //The amount of digital paging on both sides
//Constructor initialization
- public function __construct($_total, $_pagesize) {
- $this->total = $_total ? $_total : 1;
- $this->pagesize = $_pagesize;
- $this->pagenum = ceil($this->total / $this->pagesize);
- $this->page = $this->setPage();
- $this->limit = " LIMIT ".($this->page-1)*$this->pagesize.",$this->pagesize";
- $this->url = $this->setUrl();
- $ this->bothnum = 2;
- }
//Interceptor
- private function __get($_key) {
- return $this->$_key;
- }
//Get the current page number
- private function setPage() {
- if (!empty($_GET['page'])) {
- if ($_GET['page'] > 0) {
- if ($_GET['page'] > $this->pagenum) {
- return $this->pagenum;
- } else {
- return $_GET['page'];
- }
- } else {
- return 1 ;
- }
- } else {
- return 1;
- }
- }
//Get address
- private function setUrl() {
- $_url = $_SERVER["REQUEST_URI"];
- $ _par = parse_url($_url);
- if (isset($_par['query'])) {
- parse_str($_par['query'],$_query);
- unset($_query['page']);
- $_url = $_par['path'].'?'.http_build_query($_query);
- }
- return $_url;
- } //Digital directory
- private function pageList() {
- for ($i=$this ->bothnum;$i>=1;$i--) {
- $_page = $this->page-$i;
- if ($_page $_pagelist .= ' url.'&page='.$_page.'">'.$_page.' ';
- }
- $_pagelist .= ' '.$this->page.' ';
- for ($i=1;$ibothnum;$i++) {
- $_page = $this->page+$i;
- if ($_page > $this->pagenum) break;
- $_pagelist .= ' '.$_page.' ';
- }
- return $_pagelist;
- }
//Homepage
- private function first() {
- if ($this->page > $this->bothnum+1) {
- return ' 1 .. .';
- }
- }
//Previous page
- private function prev() {
- if ($this->page == 1) {
- return 'Previous page';
- }
- return ' Previous page ';
- }
//Next page
- private function next() {
- if ($this->page = = $this->pagenum) {
- return 'next page';
- }
- return ' Next page ';
- }
//Last page
- private function last() {
- if ($this->pagenum - $this->page > $this->bothnum) {
- return ' ...'.$this->pagenum.' ';
- }
- }
/ /Paging information
- public function showpage() {
- $_page .= $this->first();
- $_page .= $this->pageList();
- $_page .= $this->last( );
- $_page .= $this->prev();
- $_page .= $this->next();
- return $_page;
- }
- }
- ?>
-
Copy code
Pagination style:
Instructions for use:
-
-
$_page = new Page($_total,$_pagesize); //Where $_total is the total number of items in the data set, $_pagesize is the number displayed on each page.
- ?>
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31