Paging Class, PHP paging class
page.class.php
1
Php2 /* 3 * PHP Paging class4 * @package Page5 * @Created 2013-03-276 * @Modify 2013-03-277 * @link http://www.60ie.net8 * Example:9 $myPage =new Pager (1300,intval ($CurrentPage));Ten $pageStr = $myPage->getpagercontent (); One echo $pageStr; A */ - classPager { - Private $pageSize= 10; the Private $pageIndex;//Page Number - Private $totalNum;//Total Data - - Private $totalPagesCount;//Total Pages + - Private $PAGEURL;// + Private Static $_instance; A at Public function__construct ($p _totalnum,$p _pageindex,$p _pagesize= 10,$p _initnum=3,$p _initmaxnum=5) { - if(!isset($p _totalnum) || !isset($p _pageindex)) { - die("Pager Initial error" ); - } - - $this->totalnum =$p _totalnum;//Total Data in $this->pageindex =$p _pageindex; - $this->pagesize =$p _pagesize; to $this->initnum=$p _initnum; + $this->initmaxnum=$p _initmaxnum; - $this->totalpagescount=Ceil($p _totalnum/$p _pagesize); the $this->pageurl=$this-_getpageurl (); * $ $this-_initpagerlegal ();Panax Notoginseng } - the + /** A * Gets the current URL string that removes the page part the * + * @return String URL - */ $ Private function_getpageurl () { $ $CURRENTURL=$_server["Request_uri"];//get URI - $ARRURL=Parse_url($CURRENTURL);//parse URI, return an associative array - $urlQuery=$ARRURL["Query"];//gets the value of the array key as query the //Replace the "? Page= page Number" in the URI with "? Page" - if($urlQuery){ Wuyi //$urlQuery = Preg_replace ("/(^|&) page=". $this->pageindex. " /"," ", $urlQuery); the $urlQuery= ""; - $CURRENTURL=Str_replace($ARRURL["Query"],$urlQuery,$CURRENTURL); Wu Echo $CURRENTURL; - if($urlQuery){ About $CURRENTURL. = "&page"; $}Else{ - $CURRENTURL. = "Page"; - } -}Else { A $CURRENTURL. = "? Page"; + } the - return $CURRENTURL; $ the } the /* the * Set page parameter legitimacy the * @return void - */ in Private function_initpagerlegal () the { the //fixed page number when page number is not valid About if((!Is_numeric($this->pageindex)) | |$this->pageindex<1) the { the $this->pageindex=1; the}ElseIf($this->pageindex >$this-totalpagescount) + { - $this->pageindex=$this-Totalpagescount; the } Bayi } the the Public functiongetpagercontent () { - $str= ""; - //Home Previous Page the /*if ($this->pageindex==1) the { the $str. = "Home". " \ n "; the $str. = "Previous page". " \ n "." \ n "; - }else the { the $str. = "Pageurl}=1 ' class= ' tips ' title= ' home ' > Home". " \ n "; the $str. = "pageurl}=". ($this->pageindex-1). "' class= ' tips ' title= ' previous > prev '. " \ n "." \ n "; 94 } the */ the if($this->pageindex!=1){ the $str. = "$this->pageurl}=1 ' class= ' tips ' title= ' Home > Home '. \ n "; 98 $str. = "$this->pageurl}= ". ($this->pageindex-1). "' class= ' tips ' title= ' previous ' > prev '." \ n "." \ n "; About } - /*30s 102 page paging logic except for the first and last pages103 104 */ the //below 10 pages (inclusive)106 $currnt=""; 107 if($this->totalpagescount<=10) 108 {109 the for($i= 1;$i<=$this->totalpagescount;$i++)111 the { 113 if($i==$this-PageIndex) the{$currnt= "class= ' current '";} the Else the{$currnt=""; } 117 $str. = "$this->pageurl}={$i} ' {$currnt}>$i"." \ n " ; 118 } 119}Else //more than 10 pages -{if($this->PAGEINDEX<3)//The current page is less than 3121 { 122 for($i= 1;$i<=3;$i++) 123 { 124 if($i==$this-PageIndex) the{$currnt= "class= ' current '";} 126 Else 127{$currnt=""; } - $str. = "$this->pageurl}={$i} ' {$currnt}>$i"." \ n " ; 129 } the 131 $str.="..."." \ n "; the 133 for($i=$this->totalpagescount-3+1;$i<=$this->totalpagescount;$i++)//function 1134 { 135 $str. = "$this->pageurl}={$i} ' >$i"." \ n " ;136 137 } 138}ElseIf($this->PAGEINDEX<=5)//5 >= Current page >= 3139 { $ for($i= 1;$i<= ($this->PAGEINDEX+1);$i++) 141 { 142 if($i==$this-PageIndex)143{$currnt= "class= ' current '";} 144 Else 145{$currnt=""; } 146 $str. = "$this->pageurl}={$i} ' {$currnt}>$i"." \ n " ;147 148 } 149 $str.="..."." \ n "; Max 151 for($i=$this->totalpagescount-3+1;$i<=$this->totalpagescount;$i++)//function 1 the { 153 $str. = "$this->pageurl}={$i} ' >$i"." \ n " ;154 155 }156 157}ElseIf(5<$this->pageindex &&$this->pageindex<=$this->TOTALPAGESCOUNT-5)//the current page is greater than 5 and is less than the total number of pages-5158 159 { the 161 for($i= 1;$i<=3;$i++) 162 { 163 $str. = "$this->pageurl}={$i} ' >$i"." \ n " ; 164 } 165 $str.="..."; 166 for($i=$this->pageindex-1;$i<=$this->pageindex+1 &&$i<=$this->totalpagescount-5+1;$i++) 167 { 168 if($i==$this-PageIndex)169{$currnt= "class= ' current '";} the Else 171{$currnt=""; } 172 $str. = "$this->pageurl}={$i} ' {$currnt}>$i"." \ n " ; 173 } 174 $str.="...";175 176 for($i=$this->totalpagescount-3+1;$i<=$this->totalpagescount;$i++) 177 { 178 $str. = "$this->pageurl}={$i} ' >$i"." \ n " ;179 the } 181}Else 182 {183 184 for($i= 1;$i<=3;$i++) 185 { 186 $str. = "$this->pageurl}={$i} ' >$i"." \ n " ; 187 } 188 $str.="..."." \ n ";189 the for($i=$this->totalpagescount-5;$i<=$this->totalpagescount;$i++)//function 1191 { 192 if($i==$this-PageIndex)193{$currnt= "class= ' current '";} 194 Else 195{$currnt=""; } 196 $str. = "$this->pageurl}={$i} ' {$currnt}>$i"." \ n " ;197 198 } 199 } $ 201 }202 203 204 205 206 /*207 208 end of page pagination logic except the first209 About */211 212 //Next Last page213 /*if ($this->pageindex== $this->totalpagescount)214 { 215 $str. = "\ n". " Next page "." \ n "; 216 $str. = "Last". " \ n "; 217 }else218 { 219 $str. = "\ n". " Pageurl}= ". ($this->pageindex+1). "' class= ' tips ' title= ' next page ' > next page '. ' \ n "; - $str. = "pageurl}={$this->totalpagescount} ' class= ' tips ' title= ' last ' > Last". " \ n "; 221 } 222 */223 if($this->pageindex!=$this-Totalpagescount) {224 $str. = "\ n". " $this->pageurl}= ". ($this->pageindex+1). "' class= ' tips ' title= ' Next ' > Next". " \ n "; 225 $str. = "$this->pageurl}={$this->totalpagescount} ' class= ' tips ' title= ' last ' > Last '. ' \ n " ;226 }227 $str.= ""; 228 return $str; 229 } the 231 232 233 234 /** 235 * Get examples236 * @return237 */ 238 //static public Function getinstance () {239 //if (Is_null (self::$_instance)) { - //self::$_instance = new Pager ();241 // } 242 //return self::$_instance;243 // }244 245 246 } 247?>
Implementing Class Page.php
1
2 3----Pagination Demo-----
4
5 6
7
PHP 8 include "pager.class.php"; 9 $CurrentPage=isset($_get[' page '])? $_get [' Page ']:1; Ten $myPage=new Pager (1300,intval($CurrentPage)); One $pageStr $myPage-getpagercontent (); a Echo $pageStr ; What's up ? >
Style settings
1 body,html{padding:0px;margin:0px;Color:#333333;font-family:"Song Body", Arial,lucida,verdana,helvetica,sans-serif;font-size:12px;Line-height:150%;}2 3 H1,h2,h3,h4,h5,h6,ul,li,dl,dt,dd,form,img,p,label{margin:0;padding:0;Border:None;List-style-type:None;}4 5 /** Front page style **/ 6 7 . Pagination{margin:10px 0 0;padding:5px 0;text-align:Rightright;Height:20px;Line-height:20px;font-family:Arial, Helvetica, Sans-serif, "Song Body";}8 9 . Pagination a{Margin-left:2px;padding:2px 7px 2px;}Ten One . Pagination. Dot{Border:Medium None;padding:4px 8px} A - . Pagination A:link,. Pagination a:visited{Border:1px solid #dedede;Color:#696969;text-decoration:None;} - the . Pagination A:hover,. Pagination A:active,. Pagination A.current:link,. Pagination a.current:visited{Border:1px solid #dedede;Color:#fff;Background-color:#ff6600;Background-image:None;Border:#ff6600 solid 1px;} - - . Pagination. Selectbar{Border:#dedede solid 1px;font-size:12px;width:95px;Height:21px;Line-height:21px;Margin-left:10px;Display:inline} - + . Pagination A.tips{_padding:4px 7px 1px;}
Achieve results
http://www.bkjia.com/PHPjc/977084.html www.bkjia.com true http://www.bkjia.com/PHPjc/977084.html techarticle Pagination class, PHP page class page.class.php 1? PHP 2/* 3 * PHP Page Class 4 * @package page 5 * @Created 2013-03-27 6 * @Modify 2013-03-27 7 * @link http://www.60ie.net 8 * example:9 ...