External wrapper class for paging
<?php/**file:page.class.php Perfect Paging Class page */class page {private $total; Total number of records in the data table private $listRows; Each page shows the number of rows private $limit; The SQL statement uses the LIMIT clause to restrict the number of records to the private $uri; Automatically get URL request address private $pageNum; Total pages private $page;//Current page private $config = Array (' head ' = ' record ', ' prev ' = ' prev ', ' next ' = ' next ', ' first ' = ') Home ", ' last ' + '" End "); Display content in the paging information, you can set the private $listNum = 10 by the set () method; The number of default page list display/** construction method, you can set the properties of the paging Class @paramint$total calculate the total number of records for paging @paramint$listrows optional, set the number of records to display per page, default to 25 @parammixed$ Query optional, to pass parameters to the target page, either an array or a query string format @param bool optional, the default value is true, the page starts from the first page, False is the last page */public function __ Construct ($total, $listRows =25, $query = "", =true) {$this->total = $total; $this->listrows = $listRows; $this- >uri = $this->geturi ($query), $this->pagenum = ceil ($this->total/$this->listrows);/* The following judgment is used to set the current polygon */if ( !empty ($_get["page"]) {$page = $_get["page"];} Else{if () $page = 1;else$page = $this->pagenum;} if ($total > 0) {if (Preg_match ('/\d/'), $pAge) {$this->page = 1;} else{$this->page = $page;}} else{$this->page = 0;} $this->limit = "Limit". $this->setlimit ();} The/** is used to set the information for displaying paging, and it is possible to perform a coherent operation @paramstring$param is the subscript of the member Property array config @paramstring$ Value is used to set the element value corresponding to the config subscript @returnobject returns the $this of this object itself, used for */function set ($param, $value) {if (Array_key_exists ($param , $this->config)) {$this->config[$param] = $value;} return $this;} /* is not a direct call, this method allows you to use the value directly outside of the object to get the private member property limit and page values */function __get ($args) {if ($args = = "Limit" | | $args = = "Page") return $ this-> $args; elsereturn null;} /** output pagination @paramint0-7 in the specified format as parameters, used to customize the output paging structure and order of the structure, the default output of all structures @returnstring paging information content */function Fpage () {$arr = Func_ Get_args (); $html [0] = "<span class= ' p1 ' > total <b> {$this->total} </b>{$this->config[" Head " ]} </span> "; $html [1] =" page <b> ". $this->disnum ()." </b> bar "; $html [2] =" This page from <b>{$this->start ()}-{$this->end ()}</b> bar "; $html [3 ] = " <b>{$this->page}/{$this->pageNum}</b> page "; $html [4] = $this->firstprev (); $html [5] = $this->pagelist (); $html [6] = $this- >nextlast (); $html [7] = $this->gopage (); $fpage = ' <div style= ' font:12px \ ' \5b8b\4f53\ ', San-serif; " > '; if (count ($arr) < 1) $arr = Array (0, 1,2,3,4,5,6,7), for ($i = 0; $i < count ($arr); $i + +) $fpage. = $html [$arr [$i]] ; $fpage. = ' </div> '; return $fpage;} /* Private method used inside the object, */private function Setlimit () {if ($this->page > 0) return ($this->page-1) * $this->listrows. " , {$this->listrows} "; Elsereturn 0;} /* Private method used inside the object to automatically get access to the current URL */private function GetURI ($query) {$request _uri = $_server["Request_uri"]; $url = Strstr ( $request _uri, '? ') ? $request _uri: $request _uri. '? '; if (Is_array ($query)) $url. = Http_build_query ($query), else if ($query! = ") $url. =" & ". Trim ($query,"?& "); $arr = Parse_url ($url), if (Isset ($arr ["Query"]) {parse_str ($arr ["Query"], $arrs), unset ($arrs ["page"]), $url = $arr ["Path"] .‘?‘. Http_build_query ($arrs);} if (Strstr ($url, '? ')) {if (subSTR ($url,-1)! = '? ') $url = $url. ' & ';} else{$url = $url. '? ';} return $url;} /* Private method used inside the object to get the number of records starting at the current page */private function start () {if ($this->total = = 0) return 0;elsereturn ($this->page-1 ) * $this->listrows+1;} /* Private method used inside the object to get the number of records at the end of the current page */private function end () {return min ($this->page * $this->listrows, $this->total );} /* Private method used inside the object to obtain operation information for the previous and first page */private function Firstprev () {if ($this->page > 1) {$str = " <a href= ' {$ This->uri}page=1 ' >{$this->config["First"]}</a> ", $str. =" <a href= ' {$this->uri}page= ". ($this->page-1). "' >{$this->config["prev"]}</a> "; return $str;}} /* Private method used inside the object to get the page list information */private function pagelist () {$linkPage = " <b>"; $inum = Floor ($this->listnum /2);/* The list */for ($i = $inum; $i >= 1; $i-) {$page = $this->page-$i; if ($page >= 1) $linkPage. = "<a href= ' {$ this->uri}page={$page} ' >{$page}</a> ";} /* Information on the current page */if ($this->pagenum > 1) $linkPage. = "<span style= ' padding:1px 2px;background: #BBB; Color:white ' >{$this->page}</span> ";/* list following the current page */for ($i =1; $i <= $inum; $i + +) {$page = $this->page+ $i; if ($page <= $this->pagenum) $linkPage. = "<a href= ' {$ this->uri}page={$page} ' >{$page}</a> "; elsebreak;} $linkPage. = ' </b> '; return $linkPage;} /* Private method used inside the object to get operation information for the next and last page */private function nextlast () {if ($this->page! = $this->pagenum) {$str = " < A href= ' {$this->uri}page= '. ($this->page+1). "' >{$this->config["Next"]}</a> "$str. =" <a href= ' {$this->uri}page= ". ($this->pagenum). "' >{$this->config["last"]}</a> "; return $str;}} /* Private method used inside the object to display and process the form jump page */private function gopage () {if ($this->pagenum > 1) {return ' <input style= "Width:20px;height:17px!important;height:18px;border:1px solid #CCCCCC;" type= "text" onkeydown= "Javascript:if ( event.keycode==13) {var page= (this.value> '. $this->pagenum. ')? '. $thIs->pagenum. ': This.value;location=\ '. $this->uri. ' Page=\ ' +page+\ '} "value=" '. $this->page. ' " ><input style= "cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type= "button" value= "GO" onclick= "Javascript:var page= (this.previoussibling.value> '. $this->pagenum. ')? '. $this->pagenum ': this.previoussibling.value;location=\ '. $this->uri. ' Page=\ ' +page+\ ' \ ' > ';}} /* Private method used inside the object to get the number of record bars displayed on this page */private function Disnum () {if ($this->total > 0) {return $this->end ()-$this- >start () +1;} Else{return 0;}}}
Call
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Instance six pagination processing