Class PAGE {
//Start of class /***************************************************** **** * $total total number of records * $pageNum number of items displayed on each page * $url = '' link * $page->StartPage (display category statistics, character category/number paging, jump) ;
* $page->StartPage(true/false, true/false, true/false);
* site http://bbs.it-home.org
************ **********************************************/
private $total; //Total number of records
private $pageNum; //Per page Display number
private $page; //Current number of pages
private $pages; //Total number of pages
private $url; //Page url
private $Aque; //URL parameters
/* Constructor */
public function PAGE($total, $pageNum, $url='?'){
$this->total = $total; //Total number of records.
$this->pageNum = $pageNum; //Per page Display number.
$this->url = $this->StrSift($url); //Determine whether the value of $url is legal.
$this->Aque = $_GET; //The parameters originally passed by the page .
$this->page = $this->StrSift($_GET['page']); //Current page GET (global variable) mode parameters, current page number.
$this->page = is_numeric( $this->page) ? $this->page : 1; //When the current page number is not a number, set it to 1.
$this->pages = ceil($total/$pageNum); //Total number of pages.
if($this->page<1) $this->page = 1; //When the page number is less than 1, set it to 1.
//if($this- >page>$this->pages) $this->page = $this->pages; //When the page number is greater than the maximum page number, set it to the maximum page number.
}
/********************
* Paging method
*******************/
function StartPage($str, $view=true, $jump=true){
if($view==true) $PageStr .= $this->GetCount(); //Paging statistics
if ($str=='str') $PageStr .= $this->GetPageStr(); //Select the character paging format
else $PageStr .= $this->GetPageNum(); //Select the numeric paging format
if($jump==true) $PageStr .= $this->JumpSelect(); //Jump
return $PageStr;
}
/********************************************
* Show statistics. Format: 5 records in total Page: 2/3
****************************************** ***********/
function GetCount(){
$CountStr = "Total". $this->total ." Records Page:".$this->page."/". $this->pages." ";
return $CountStr;
}
/***********************************************
* Pagination format 1: First page Previous page Next page Last page
************************************ ************/
function GetPageStr(){
$url = $ this->url; //Get the URL
//Process the URL parameters: the key of 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 page previous page
switch($this->page){
case $this->page<=1: $pagestr .= "Homepage "; $pagestr .= "Previous page "; break; default: $pagestr . = "Homepage ";
$pagestr .= "Previous page ";
}
//Next page last page
switch($this->page){
case $this->page>=$this->pages:
$pagestr .= "Next page ";
$pagestr .= "Last page ";
break;
default:
$pagestr .= "Next page ";
$pagestr .= "< a href='".$url."?page=$this->pages$Sque'>Last page ";
}
//Return the paging string.
return $ pagestr;
}
/***************************************************** *******
* The pagination format is as follows: a total of 4307 record pages: 1/72 1 2 3 4 5 6 7 8 9 10
**************** ********************************************/
function GetPageNum(){
$url = $this->url;
//Process the URL parameters: the key of the array is the URL variable , 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:
//Before the paging number: < << switch($this->page){
case $this->page>1:
$pagestr .= "< ";
$pagestr .= "<< ";
break;
default:
$pagestr .= "< "; $pagestr . = "<< "; } //Paging numbers: 1 2 3 4 5 6 There are 6 paging links on the left of the current page number and 6 paging 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< /a> ";
}
//After paging numbers: > >>
switch($this->page){
case $this->page<$this->pages:
$pagestr .= ">> ";
$pagestr .= "> ";
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 ";
}
}
}
//Return the paging string.
return $pagestr;
}
/**************************
* Define jump page. BEGIN
************************ ******/
function JumpSelect(){
$url = $this->url;
//Process the URL parameters: The key of 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";
//Return 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 result in "??".
$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;
}
//End of class
}
?>
Copy code
Friends who are interested can also refer to the following articles:
A good php paging class code
A practical php paging class
Pagination style sheet:
/*Drop-down menu or text input box style*/
#JumpSelect{
background:#159bd0;
border:1px solid #ffff66;
color :#ffff66;
width:37px;
font-size:11px;
padding:0 0 0 0;
margin:0 0 0 0;
SCROLLBAR-FACE-COLOR: #d0dff7;
SCROLLBAR-HIGHLIGHT-COLOR: # d0dff7;
SCROLLBAR-SHADOW-COLOR: #FFFFFF;
SCROLLBAR-3DLIGHT-COLOR: #FFFFFF;
SCROLLBAR-ARROW-COLOR: #ffffff;
SCROLLBAR-TRACK-COLOR: #ffffff;
SCROLLBAR-DARKSHADOW-COLOR: # d0dff7;
base-color: #ededed;
scrollbar-arrow-color: #000;
scrollbar-highlight-color: #fafafa;
scrollbar-shadow-color: #fafafa;
scrollbar-track-color: #ededed;
scrollbar-face-color: #fafafa;
scrollbar-darkshadow-color: #ededed;
scrollbar-3dlight-color: #ededed;
}
Copy code