Classic PHP Tutorial Page class-PHP General Page class
<?php
class my_lib_pages{
Private $each _disnums;//The number of entries displayed per page
private $nums//Total number of entries
var $current _page;//The currently selected page
Private $sub _pages;//The number of pages per display
private $pageNums//Total pages
private $page _array = Array ();//To construct the
of pagination
private $subPage _link;//each page link
Private $subPage _type;//Displays the type of pagination
/*
__construct is a subpages constructor that runs automatically when a class is created.
@ $each _disnums The number of entries displayed per page
@nums Total number of entries
@current_num currently selected page
@sub_pages number of pages per display
@subPage_link links for each page
@subPage_type Display the type of pagination
when @subpage_type=1 for general paging mode
Example: Total 4,523 records, each page shows 10, the current 1th 453 page [first] [prev] [Next page] [last page]
The classic paging style when @subpage_type=2
Example: Current 1th 453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next page] [last]
*/
function __construct ($each _disnums, $nums, $current _page, $sub _pages, $subPage _link, $subPage _type) {
$this->each_disnums=intval ($each _disnums);
$nums = $nums ==0? 1: $nums;
$this->nums=intval ($nums);
$this->pagenums=ceil ($nums/$each _disnums);
$this->current_page=intval ($current _page);
$this->current_page= $this->current_page<=0? 1: $this->current_page;
$this->current_page= $this->current_page > $this->pagenums? 1: $this->current_page;
$this->sub_pages=intval ($sub _pages);
$this->subpage_link= $subPage _link;
$this->show_subpages ($subPage _type);
//echo $this->pagenums. " --"$this->sub_pages;
}
/*
__destruct destructors that are invoked when a class is not used to release resources.
*/
function __destruct () {
unset ($each _disnums);
unset ($nums);
unset ($current _page);
unset ($sub _pages);
unset ($pageNums);
unset ($page _array);
unset ($subPage _link);
unset ($subPage _type);
}
/*
show_subpages functions are used in constructors. and used to determine what kind of paging
*/
function Show_subpages ($subPage _type) {
if ($subPage _type = = 1) {
$this->subpagecss1 ();
}elseif ($subPage _type = = 2) {
$this->subpagecss2 ();
}
}
/*
the function used to initialize the array of pagination.
*/
function Initarray () {
for ($i =0 $i < $this->sub_pages; $i + +) {
$this->page_array[$i]= $i;
}
return $this->page_array;
}
/*
Construct_num_page The function is used to construct the displayed entry
even: [1][2][3][4][5][6][7][8][9][10]
*/
function Construct_num_page () {
if ($this->pagenums < $this->sub_pages) {
$current _array=array ();
for ($i =0 $i < $this->pagenums; $i + +) {
$current _array[$i]= $i +1;
}
}else{
$current _array= $this->initarray ();
if ($this->current_page <= 3) {
for ($i =0 $i <count ($current _array), $i + +) {
$current _array[$i]= $i +1;
}
}elseif ($this->current_page <= $this->pagenums && $this->current_page > $this-> pagenums-$this->sub_pages + 1) {
for ($i =0 $i <count ($current _array), $i + +) {
$current _array[$i]= ($this->pagenums)-($this->sub_pages) +1+ $i;
}
}else{
for ($i =0 $i <count ($current _array), $i + +) {
$current _array[$i]= $this->current_page-2+ $i;
}
}
}
return $current _array;
}
/*
constructing Normal Mode paging
Total 4,523 Records, each page shows 10, the current 1th 453 page [first] [prev] [Next page] [last]
*/
function SubPageCss1 () {
$subPageCss 1str= "";
$subPageCss 1str.= "altogether" $this->nums. " Record, ";
$subPageCss 1str.= "show per page". $this->each_disnums. " Article, ";
$subPageCss 1str.= "Current section" $this->current_page. " /". $this->pagenums." Page ";
if ($this->current_page > 1) {
$firstPageUrl = $this->subpage_link. Rezoning;
$prewPageUrl = $this->subpage_link. ($this->current_page-1);
$subPageCss 1str.= "[<a href= ' $firstPageUrl ' > Home </a>]";
$subPageCss 1str.= "[<a href= ' $prewPageUrl ' > Prev </a>]";
}else {
$subPageCss 1str.= "[Home]";
$subPageCss 1str.= "[prev]";
}
if ($this->current_page < $this->pagenums) {
$lastPageUrl = $this->subpage_link. $this->pagenums;
$NEXTPAGEURL = $this->subpage_link. ($this->current_page+1);
$subPageCss 1str.= "[<a href= ' $nextPageUrl ' > Next page </a>]";
$subPageCss 1str.= "[<a href= ' $lastPageUrl ' > End </a>]";
}else {
$subPageCss 1str.= "[next page]";
$subPageCss 1str.= "[Last]";
}
return $SUBPAGECSS 1Str;
}
/*
Pagination
of
Construction Classic mode
Current 1th 453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next page] [last]
*/
function SubPageCss2 () {
$subPageCss 2str= "";
$subPageCss 2str.= "current <span style=color:red;>". $this->current_page. " </span>/". $this->pagenums." Page ";
if ($this->current_page > 1) {
$firstPageUrl = $this->subpage_link. Rezoning;
$prewPageUrl = $this->subpage_link. ($this->current_page-1);
$subPageCss 2str.= "<a href= ' $firstPageUrl ' > Home </a>";
$subPageCss 2str.= "<a href= ' $prewPageUrl ' ><<</a>";
}else {
$subPageCss 2str.= "<span class=disabled> home </span>";
$subPageCss 2str.= "<span class=disabled><<</span>";
}
$a = $this->construct_num_page ();
for ($i =0; $i <count ($a); $i + +) {
$s = $a [$i];
if ($s = = $this->current_page) {
$subPageCss 2str.= "<span style= ' color:red;font-weight:bold; > ". $s." </span> ";
}else{
$url = $this->subpage_link $s;
$subPageCss 2str.= "<span class=current><a href= ' $url ' > '. $s." </a></span> ";
}
}
if ($this->current_page < $this->pagenums) {
$lastPageUrl = $this->subpage_link. $this->pagenums;
$nextPageUrl = $this->subpage_link. ($this->current_page+1);
$subPageCss 2str.= "<a href= ' $nextPageUrl ' >>></a>";
$subPageCss 2str.= "<a href= ' $lastPageUrl ' > Last </a>";
}else {
$subPageCss 2str.= "<span class=disabled>>></span>";
$subPageCss 2str.= "<span class=disabled> last </span>";
}
return $SUBPAGECSS 2Str;
}
}
?>