<style type= "Text/css Tutorial" > Two PHP tutorial pagination instance Code
A.pagecool,.pagecoolselect,.pagecoolpre,.pagecoolnext,.pageinfo,.curtotalx,.pagecoolprex,.pagecoolnextx{float: Left;height:20px;font-family:arial, song body, color: #444; Font-weight:bold}
A.pagecool,.pagecoolselect{width:22px;height:18px;font-weight:bold;border: #ccc 1px solid;margin:0 3px 0 3px;text-align:center;line-height:18px}
A.pagecool{text-decoration:none;color: #444; background: #fbf9f9;d Isplay:block}
A.pagecool:hover,.pagecoolselect{color: #f00; background: #ffc}
. pagecoolpre,.pagecoolnext{margin:0 8px 0 8px}
. pageinfo{line-height:20px;margin:0 0 0 8px;font-family:verdana,arial}
. PageInfo Span{color: #f60}
. pagecoolprex,.pagecoolnextx{margin:0 0 0 5px}
. Curtotalx{color: #666; line-height:20px;margin:0 2px 0 0;font-weight:normal;font-family:verdana,arial;text-align:right}
</style>
<?php
!function_exists (' cdstr ') && exit (' forbidden ');
Class Wrzc_netpage {
Private $page _name= "P";
Private $pagesize =10;//Display the number of record bars per page
Private $total The total number of =0;//records
Private $pagebarnum number of =10;//bar.
Private $totalpage = 0;
Private $linkhead = "";//url address Header
Private $current _pageno=1;//Current page
Public function __construct ($total, $pagesize =10) {
if ((!is_int ($total)) | | ($total <0)) Die ("Total number of records" Error!) ");
if ((!is_int ($pagesize)) | | ($pagesize <0)) Die ("pagesize wrong!") ");
$this->set ("Total", $total);
$this->set ("pagesize", $pagesize);
$this->set (' Totalpage ', ceil ($total/$pagesize));
}
Public function set ($var, $value) {
if (In_array ($var, Get_object_vars ($this))
$this-> $var = $value;
else {
throw new Pb_page_exception ("Error in Set ():". $var. "Does not belong to pb_page!");
}
}
Public Function Get_linkhead () {
$this->set_current_page ();
if (Empty ($_server[' query_string ')) {
$this->linkhead=$_server[' Request_uri ']. $this->page_name. " =";
}else{
if (Isset ($_get[$this->page_name])) {
$this->linkhead=str_replace ($this->page_name. = '. $this->current_pageno, $this->page_name. ' = ', $_server[' Request_uri ']);
} else {
$this->linkhead=$_server[' Request_uri ']. ' & '. $this->page_name. ' =';
}
}
}
/* Returns the address value for the specified page * *
Public Function Get_url ($pageno =1) {
if (Empty ($this->linkhead)) $this->get_linkhead ();
Return Str_replace ($this->page_name. ' = ', $this->page_name. ' = '. $pageno, $this->linkhead);
}
/* Current Page */
Public Function Set_current_page ($current _pageno=0) {
if (Empty ($current _pageno)) {
if (Isset ($_get[$this->page_name])) {$this->current_pageno=intval ($_get[$this->page_name]);
}else{
$this->current_pageno=intval ($current _pageno);
}
if ($this->current_pageno> $this->totalpage) header ("location:./");//$this->current_pageno=1
}
Public Function Set_format ($STR) {return $this->format_left. $str. $this->format_right}
/* Get Display "next Page" * *
Public Function Next_page () {
if ($this->current_pageno< $this->totalpage) {
Return ' <a href= '. $this->get_url ($this->current_pageno+1). ' " > '. $this->next_page. ' </a> ';
}
Return ";
}
/* Get Display "Previous page" * *
Public Function Pre_page () {
if ($this->current_pageno>1) {return ' <a href= '. $this->get_url ($this->current_pageno-1). " > '. $this->pre_page. ' </a> ';}
Return ";
}
/* Get Display "Home" * *
Public Function First_page () {return ' <a href= '. $this->get_url (1). ' " > '. $this->first_page. " </a> ";}
/* Get Display "last" * *
Public Function Last_page () {return ' <a href= '. $this->get_url ($this->totalpage). " > '. $this->last_page. ' </a> ';}
Public Function Nowbar () {
if ($this->totalpage > 1) {
$begin = $this->current_pageno-ceil ($this->PAGEBARNUM/2);
$begin = ($begin >=1) $begin: 1;
$return = ';
for ($i = $begin; $i < $begin + $this->pagebarnum; $i + +) {
if ($i <= $this->totalpage) {
if ($i!= $this->current_pageno) {
$return. = "<a href=". $this->get_url ($i). "Class=pagecool>". $i. ' </a> ';
}else {
$return. = ' <div class=pagecoolselect> '. $i. ' </div> ';
}
}else{
Break
}
}
Unset ($begin);
}
return $return;
}
/* "Previous page" * *
Public Function Pre_bar () {
if ($this->current_pageno>ceil ($this->pagebarnum/2)) {
$pageno = $this->current_pageno-$this->pagebarnum;
if ($pageno <=0) $pageno = 1;
return $this->set_format (' <a href= '. $this->get_url ($pageno). " > '. $this->pre_bar. " </a> ");
}
return $this->set_format (' <a href= '. $this->get_url (1). " > '. $this->pre_bar. " </a> ");
}
/* "Next page" * *
Public Function Next_bar () {
if ($this->current_pageno< $this->totalpage-ceil ($this->pagebarnum/2)) {
$pageno = $this->current_pageno+ $this->pagebarnum;
return $this->set_format (' <a href= '. $this->get_url ($pageno). " > '. $this->next_bar. " </a> ");
}
return $this->set_format (' <a href= '. $this->get_url ($this->totalpage). " > '. $this->next_bar. " </a> ");
}
/* Jump * *
Public Function Select () {
$return = ' <select name= ' pb_page_select ' onchange= ' window.location.href= '. $this->linkhead. " +this.options[this.selectedindex].value ">";
For ($i =1 $i <= $this->totalpage; $i + +) {
if ($i = = $this->current_pageno) {
$return. = ' <option value= '. $i. ' selected> '. $i. ' </option> ';
}else{
$return. = ' <option value= '. $i. ' > ' $i. ' </option> ';
}
}
$return. = ' </select> ';
return $return;
}
Public Function Pagebar ($mode =1) {
Global $global;
$this->set_current_page ();
$this->get_linkhead ();
Return ("A total of <font color=red><b>". $this->total. " </b></font> Records. ");
Switch ($mode) {
Case 1:
$this->pre_page= ' <img src= '. $global [' Www_2domain ']. ' /images/precool.gif title= on a page class=pagecoolpre> ';
$this->next_page= ' <img src= '. $global [' Www_2domain ']. ' /images/nextcool.gif title= next page class=pagecoolnext> ';
return $this->pre_page (). $this->nowbar (). $this->next_page (). ' <div class=pageinfo> <span> '. $this->current_pageno. ' </span> page/Total <span> ' $this->totalpage. ' </span> page </div> ';
Break
Case 2:
$this->pre_page= ' <img src= '. $global [' Www_2domain ']. ' /images/precoolx.gif title= on a page class=pagecoolprex> ';
$this->next_page= ' <img src= '. $global [' Www_2domain ']. ' /images/nextcool.gif title= next page class=pagecoolnextx> ';
Return ' <div class=curtotalx> '. $this->current_pageno. ' /'. $this->totalpage. ' </div> $this->pre_page (). $this->next_page ();
Return ' <div class=curtotalx> '. $this->total. ' /'. $this->current_pageno. ' /'. $this->totalpage. ' </div> $this->pre_page (). $this->next_page ();
Break
Case 3:
$this->pre_page= ' <img src= '. $global [' Www_2domain ']. ' /images/precoolx.gif title= on a page class=pagecoolprex> ';
$this->next_page= ' <img src= '. $global [' Www_2domain ']. ' /images/nextcool.gif title= next page class=pagecoolnextx> ';
Return ' <div class=curtotalx> '. $this->current_pageno. ' Page/Total '. $this->totalpage. ' Page </div> '. $this- >pre_page (). $this->next_page ();
Break
}
}
}
?>
Code two
<?php
!function_exists (' cdstr ') && exit (' forbidden ');
Class Uobarpage {
Private $page _name= "P";//page label, used to control the URL page. For example, the Pb_page in xxx.php?pb_page=2.
Private $pagesize =10;//Display the number of record bars per page
Private $total The total number of =0;//records
Private $pagebarnum =10;//Control the number of record bars.
Private $totalpage Total Pages =0;//
Private $linkhead = "";//url address Header
Private $current _pageno=1;//Current page
/**
* Display symbol settings
*/
Private $next _page= ' > ';//Next page
Private $pre _page= ' < ';//Previous Page
Private $first _page= ' first ';//Home
Private $last _page= ' last ';/end
Private $pre _bar= ' << '/previous page bar
Private $next _bar= ' >> '/next page bar
Private $format _left= ' [';
Private $format _right= '] ';
Public function __construct ($total, $pagesize =10) {
if ((!is_int ($total)) | | ($total <0)) Die ("Total number of records" Error!) ");
if ((!is_int ($pagesize)) | | ($pagesize <0)) Die ("pagesize wrong!") ");
$this->set ("Total", $total);
$this->set ("pagesize", $pagesize);
$this->set (' Totalpage ', ceil ($total/$pagesize));
}
Public function set ($var, $value)
{
if (In_array ($var, Get_object_vars ($this))
$this-> $var = $value;
else {
throw new Pb_page_exception ("Error in Set ():". $var. "Does not belong to pb_page!");
}
}
/**
* Get the default URL to obtain the specified URL address
*
*/
/*
Public Function Get_linkhead () {
$this->set_current_page ();
$this->linkhead=$_server[' php_self ']. $this->page_name. " =";
}
*/
Public Function Get_linkhead () {
$this->set_current_page ();
if (Empty ($_server[' query_string ')) {
$this->linkhead=$_server[' Request_uri ']. $this->page_name. " =";
}else{
if (Isset ($_get[$this->page_name])) {
$this->linkhead=str_replace ($this->page_name. = '. $this->current_pageno, $this->page_name. ' = ', $_server[' Request_uri ']);
} else {
$this->linkhead=$_server[' Request_uri ']. ' & '. $this->page_name. ' =';
}
}
}
/**
* Returns the address value for the specified page
*/
Public Function Get_url ($pageno =1)
{
if (Empty ($this->linkhead)) $this->get_linkhead ();
Return Str_replace ($this->page_name. ' = ', $this->page_name. ' = '. $pageno, $this->linkhead);
}
/**
* Set the current page
*
*/
Public Function Set_current_page ($current _pageno=0) {
if (Empty ($current _pageno)) {
if (Isset ($_get[$this->page_name])) {
$this->current_pageno=intval ($_get[$this->page_name]);
}
}else{
$this->current_pageno=intval ($current _pageno);
}
if ($this->current_pageno> $this->totalpage) header ("location:./");//////////$this->current_pageno=1/ ///////////
}
Public Function Set_format ($STR) {
Return $this->format_left. $str $this->format_right;
}
/**
* Get the code that displays the next page
*
* @return String
*/
Public Function Next_page () {
if ($this->current_pageno< $this->totalpage) {
Return ' <a href= '. $this->get_url ($this->current_pageno+1). ' " > '. $this->next_page. ' </a> ';
}
Return ";
}
/**
* Get the code that shows "previous page"
*
* @return String
*/
Public Function Pre_page () {
if ($this->current_pageno>1) {
Return ' <a href= '. $this->get_url ($this->current_pageno-1). ' " > '. $this->pre_page. ' </a> ';
}
Return ";
}
/**
* Get the code to display "Home page"
*
* @return String
*/
Public Function First_page () {
Return ' <a href= '. $this->get_url (1). ' " > '. $this->first_page. " </a> ";
}
/**
* Get the code that shows "last"
*
* @return String
*/
Public Function Last_page () {
Return ' <a href= '. $this->get_url ($this->totalpage). ' " > '. $this->last_page. ' </a> ';
}
Gyl1
Public Function Nowbar () {
$begin = $this->current_pageno-ceil ($this->PAGEBARNUM/2);
$begin = ($begin >=1) $begin: 1;
$return = ';
for ($i = $begin; $i < $begin + $this->pagebarnum; $i + +)
{
if ($i <= $this->totalpage) {
if ($i!= $this->current_pageno)
$return. = ' <a href= '. $this->get_url ($i). ' " > '. ' <span class=page1 onmouseo Tutorial ver=this.style.background= "FFFFCC" onmouseout=this.style.background= "FBF9F9" > <b> '. $i. ' </b></span> '. ' </a> ';
Else
$return. = ' <span class=page2><b> '. $i. ' </b></span> ';
}else{
Break
}
}
Unset ($begin);
return $return;
}
/**
* Get the code that shows "previous page bar"
*
* @return String
*/
Public Function Pre_bar ()
{
if ($this->current_pageno>ceil ($this->pagebarnum/2)) {
$pageno = $this->current_pageno-$this->pagebarnum;
if ($pageno <=0) $pageno = 1;
return $this->set_format (' <a href= '. $this->get_url ($pageno). " > '. $this->pre_bar. " </a> ");
}
return $this->set_format (' <a href= '. $this->get_url (1). " > '. $this->pre_bar. " </a> ");
}
/**
* Get the code that displays the next page bar
*
* @return String
*/
Public Function Next_bar ()
{
if ($this->current_pageno< $this->totalpage-ceil ($this->pagebarnum/2)) {
$pageno = $this->current_pageno+ $this->pagebarnum;
return $this->set_format (' <a href= '. $this->get_url ($pageno). " > '. $this->next_bar. " </a> ");
}
return $this->set_format (' <a href= '. $this->get_url ($this->totalpage). " > '. $this->next_bar. " </a> ");
}
/**
* Get the code to display the Jump button
*
* @return String
*/
Public Function Select ()
{
$return = ' <select name= ' pb_page_select ' onchange= ' window.location.href= '. $this->linkhead. " +this.options[this.selectedindex].value ">";
For ($i =1 $i <= $this->totalpage; $i + +)
{
if ($i = = $this->current_pageno) {
$return. = ' <option value= '. $i. ' selected> '. $i. ' </option> ';
}else{
$return. = ' <option value= '. $i. ' > ' $i. ' </option> ';
}
}
$return. = ' </select> ';
return $return;
}
/**
* Get the values limit need in the MySQL tutorial statement
*
* @return String
*/
Public Function Limit2 () {
Return ("A total of <font color=red><b>". $this->total. " </b></font> Records. ");
Return (' A total of <font color=red> '. $this->total. ') </font> Records. <font color=red> '. $this->current_pageno). " </font> page/Total <font color=red> ". $this->totalpage. ' </font> page ';
Return (' <span style= "HEIGHT:20PX;PADDING-TOP:3PX; > Total <b> ' $this->current_pageno. '/'. $this->totalpage. ' </b> page </span> ');
}
Public Function Pagebar ($mode =1)
{Global $global;
$this->set_current_page ();
$this->get_linkhead ();
Switch ($mode)
{
Case ' 1 ':
$this->next_page= ' <img src= '. $global [' Www_2domain ']. ' /images/next.gif border=0 align=absmiddle alt= next page > ';
$this->pre_page= ' <img src= '. $global [' Www_2domain ']. ' /images/pre.gif border=0 align=absmiddle alt= prev > ';
return $this->pre_page (). $this->nowbar (). $this->next_page ();
return $this->pre_page (). $this->nowbar (). $this->next_page (). ' $this->select (). ' Page ';
Break
}
}
}
?>