-
Class PAGE {
- Class start
- /********************************************************
- * Total number of $total records
- * $pageNum the number of bars displayed per page
- * $url = ' link
- * $page->startpage (display categorical statistics, character classification/digital paging, jump);
- * $page->startpage (true/false, True/false, True/false);
- * Site http://bbs.it-home.org
- *********************************************************/
- Private $total; Total Records
- Private $pageNum; Number of displays per page
- Private $page; Current page
- Private $pages; Total number of pages
- Private $url; Page URL
- Private $Aque; URL parameters
- /* Constructor function */
- Public Function PAGE ($total, $pageNum, $url = '? ') {
- $this->total = $total; The total number of records.
- $this->pagenum = $pageNum; The number of displays per page.
- $this->url = $this->strsift ($url); Determines whether the value of the hash is legal.
- $this->aque = $_get; The parameters that the page originally passed.
- $this->page = $this->strsift ($_get[' page '); Current page get (global variable) mode parameter, current page number.
- $this->page = is_numeric ($this->page)? $this->page:1; When the current page number is not a number, it is set to 1.
- $this->pages = ceil ($total/$pageNum); Total pages.
- if ($this->page<1) $this->page = 1; When the page number is less than 1 o'clock, set it to 1.
- if ($this->page> $this->pages) $this->page = $this->pages; When the page number is greater than the maximum page number, it is set to the maximum page number.
- }
- /******************
- * Pagination Method
- *******************/
- function StartPage ($str, $view =true, $jump =true) {
- if ($view ==true) $PageStr. = $this->getcount (); Paging statistics
- if ($str = = ' str ') $PageStr. = $this->getpagestr (); Select the form of a character page
- else $PageStr. = $this->getpagenum (); Select the form of a digital page
- if ($jump ==true) $PageStr. = $this->jumpselect (); Jump
- return $PageStr;
- }
-
/**********************************************
- * Display statistics. Format: Total 5 records page: 2/3
- ***********************************************/
- function GetCount () {
- $COUNTSTR = "Total ". $this->total. " Records page: ". $this->page." /". $this->pages." ";
- return $CountStr;
- }
-
/***********************************************
- * Paging format one: First previous next last page
- ************************************************/
- function Getpagestr () {
- $url = $this->url; Get URL
- Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
- foreach ($this->aque as $key = + $val) {
- Switch ($key) {
- Case "page":
- $Next = $val + 1;
- $Prev = $val-1;
- Break
- Default
- $Sque. = "& $key =". $this->strsift ($val);
- }
- }
- if ($Next ==0) $Next = 2;
- Home previous Page
- Switch ($this->page) {
- Case $this->page<=1:
- $pagestr. = "Home";
- $pagestr. = "Previous page";
- Break
- Default
- $pagestr. = "Home";
- $pagestr. = "Previous page";
- }
- Next last Page
- Switch ($this->page) {
- Case $this->page>= $this->pages:
- $pagestr. = "Next page";
- $pagestr. = "Last";
- Break
- Default
- $pagestr. = "Next page";
- $pagestr. = "Pages$sque ' > Last";
- }
- Returns the paging string.
- return $pagestr;
- }
-
/***********************************************************
- * Page Format: A total of 4,307 records page: 1/72 1 2 3 4 5 6 7 8 9 10
- ************************************************************/
- function Getpagenum () {
- $url = $this->url;
- Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
- foreach ($this->aque as $key = + $val) {
- Switch ($key) {
- Case $key! = "page":
- $Sque. = "& $key =". $this->strsift ($val);
- }
- }
- Switch ($this->pages) {
- The total number of pages is greater than 12 pages:
- Case $this->pages>12:
- Pagination Digital Front:< <<
- Switch ($this->page) {
- Case $this->page>1:
- $pagestr. = "<";
- $pagestr. = "page-1). $Sque." ' ><< ";
- Break
- Default
- $pagestr. = "<";
- $pagestr. = "<<";
- }
- Number of pages: 1 2 3 4 5 6 current page left 6 pagination links, 6 pagination links on the right.
- for ($i = $this->page-6; $i <= $this->page+6; $i + +) {
- if ($i > $this->pages) break;
- if ($i = = $this->page) $pagestr. = $i. " ";
- ElseIf ($i >=1) $pagestr. = "$i";
- }
- After paging number: > >>
- Switch ($this->page) {
- Case $this->page< $this->pages:
- $pagestr. = "page+1). $Sque." ' >>> ";
- $pagestr. = "pages. $Sque." >> ";
- Break
- Default
- $pagestr. = ">";
- $pagestr. = ">>";
- }
- Break
- Default
- The total number of pages is less than 12 pages:
- for ($i =1; $i <= $this->pages; $i +) {
- Switch ($i) {
- Case $i = = $this->page:
- $pagestr. = $i. " ";
- Break
- Default
- $pagestr. = "$i";
- }
- }
- }
- Returns the paging string.
- return $pagestr;
- }
- /************************
- * Define jump pages. BEGIN
- *************************/
- function Jumpselect () {
- $url = $this->url;
- Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
- foreach ($this->aque as $key = + $val) {
- if ($key! = "page") $Sque. = "& $key =". $this->strsift ($val);
- }
- $SELECTSTR = "\ n
- $SelectStr. = "onchange=\" window.location= ' ". $url."? Page= ' +this.value+ ' ". $Sque." \ ">\n"; for ($i =1; $i <= $this->pages; $i + +) {if ($i = = $this->page) $selected = "selected"; Else $selected = ""; $SelectStr. = "$i \ n "; } $SelectStr. = "\ n";
- Returns the paging string.
- return $SelectStr;
- }
-
/**********************************
- * Filter special characters.
- ***********************************/
- Private Function Strsift ($STR) {
- $str = Str_replace ("\" "," ", $str);
- $str = Str_replace ("'", "" ", $str);
- $str = Str_replace ("[Url=file://%22,%22%22, $str/]\\", "", $str [/url]);
- $str = str_replace ("\ \", "", $str);
- $str = Str_replace (":", "", $str);
- $str = Str_replace ("?", "" ", $str); Removal will appear "??".
- $str = Str_replace (">", "", $str);
- $str = Str_replace ("<", "", $str);
- $str = str_replace ("%", "", $str);
- $str = Str_replace ("*", "", $str);
- $str = Str_replace ("&", "", $str);
- $str = Str_replace (".", "", $str);
- return $str;
- }
-
Class End
- }
- ?>
Copy Code
Interested friends, can also refer to the following article: A good PHP page class code A useful PHP paging class
Paging style sheet:
Copy Code |