PHP Classic Pagination Code class _php tutorial

Source: Internet
Author: User
Tags id3 mysql tutorial
PHP Classic Pagination Code class This is a PHP page code is a classic can automatically determine the URL parameters and then pagination of the instance code, while the last page, next page, home, last Oh, but also support the Select drop-down box jump code.

PHP Tutorial Classic Pagination Code class
This is a PHP page code is a classic can automatically determine the URL parameters and then pagination of the instance code, while customizing the page, next page, home, last Oh, but also support the Select drop-down box jump code.
*/

Class page{

var $page _name= "page";

var $next _page= ' next page ';

var $pre _page= ' previous page ';

var $first _page= ' home ';

var $last _page= ' last ';

var $pre _bar= ' << ';

var $next _bar= ' >> ';

var $format _left= ';

var $format _right= ';

var $pagebarnum = 5;

var $totalpage = 0;

var $nowindex = 1;

var $url = "";

var $offset = 0;

var $rewrite = array ();


Function page ($array)

{

if (Is_array ($array)) {

if (!array_key_exists (' Total ', $array)) $this->error (__function__, ' need a param of total ');

$total =intval ($array [' total ']);

$perpage = (array_key_exists (' Perpage ', $array))? intval ($array [' Perpage ']): 10;

$nowindex = (array_key_exists (' Nowindex ', $array))? intval ($array [' Nowindex ']): ';

$url = (array_key_exists (' url ', $array))? $array [' url ']: ';

$action = (array_key_exists (' action ', $array))? $array [' Action ']: ';
$id 0 = (array_key_exists (' id0 ', $array))? $array [' id0 ']: ';
$id 1 = (array_key_exists (' id1 ', $array))? $array [' Id1 ']: ';
$id 2 = (array_key_exists (' Id2 ', $array))? $array [' Id2 ']: ';
$id 3 = (array_key_exists (' ID3 ', $array))? $array [' ID3 ']: ';

}else{

$total = $array;

$perpage = 10;

$nowindex = ";

$url = ";

$action = ";
$id 0 = ";
$id 1 = ";
$id 2 = ";
$id 3 = ";

}

if ((!is_int ($total)) | | ($total <0)) $this->error (__function__, $total. ' is not a positive integer! ');

if ((!is_int ($perpage)) | | ($perpage <=0)) $this->error (__function__, $perpage. ' is not a positive integer! ');

if (!empty ($array [' page_name '])) $this->set (' page_name ', $array [' page_name ']);

$this->_set_nowindex ($nowindex);

$this->_set_url ($url);

$this->totalpage=ceil ($total/$perpage);

$this->offset= ($this->nowindex-1) * $perpage;

$this->action = $action;
$this->rewrite = array (' action ' = = $action, ' id0 ' = + $id 0, ' id1 ' = + $id 1, ' id2 ' = + $id 2, ' ID3 ' + $id 3);
}

function set ($var, $value)
{

if (In_array ($var, Get_object_vars ($this)))

$this $var = $value;

else {

$this->error (__function__, $var. "Does not belong to pb_page!");

}

}

function Next_page ($style = ") {
if ($this->nowindex< $this->totalpage) {
return $this->_get_link ($this->_get_url ($this->nowindex+1), $this->next_page, $style);
}
Return ". $this->next_page.";
}

function Pre_page ($style = ") {
if ($this->nowindex>1) {
return $this->_get_link ($this->_get_url ($this->nowindex-1), $this->pre_page, $style);
}
Return ". $this->pre_page.";
}

function First_page ($style = ") {
if ($this->nowindex==1) {
Return ". $this->first_page.";
}
return $this->_get_link ($this->_get_url (1), $this->first_page, $style);
}

function Last_page ($style = ") {
if ($this->nowindex== $this->totalpage| | $this->totalpage==0) {

Return ". $this->last_page.";

}

return $this->_get_link ($this->_get_url ($this->totalpage), $this->last_page, $style);

}


function Nowbar ($style = ", $nowindex _style=")

{

$plus =ceil ($this->PAGEBARNUM/2);

if ($this->pagebarnum-$plus + $this->nowindex> $this->totalpage) $plus = ($this->pagebarnum-$this totalpage+ $this->nowindex);

$begin = $this->nowindex-$plus +1;

$begin = ($begin >=1)? $begin: 1;

$return = ";

for ($i = $begin; $i < $begin + $this->pagebarnum; $i + +)

{

if ($i <= $this->totalpage) {

if ($i! = $this->nowindex)

$return. = $this->_get_text ($this->_get_link ($this->_get_url ($i), $i, $style));

Else

$return. = $this->_get_text (". $i. ');

}else{

Break

}

$return. = "n";

}

Unset ($begin);

return $return;

}

/**

* Get the code to show the Jump button

*

* @return String

*/

function Select ()

{

$return = ''; for ($i =1; $i <= $this->totalpage; $i + +) {if ($i = = $this->nowindex) {$return. = ''. $i. '; }else{$return. = ''. $i. '; }} unset ($i); $return. = '';

return $return;

}

/**

* Get the value required by limit in the MySQL tutorial statement

*

* @return String

*/

function offset ()

{

return $this->offset;

}

/**

* Control the pagination display style (you can add the corresponding style)

*

* @param int $mode

* @return String

*/

Function Show ($mode =1)

{

Switch ($mode)

{

Case ' 1 ':

$this->next_page= ' next page ';

$this->pre_page= ' previous page ';

return $this->pre_page (). $this->nowbar (). $this->next_page (). ' Section '. $this->select (). ' Page ';

Break

Case ' 2 ':

$this->next_page= ' next page ';

$this->pre_page= ' previous page ';

$this->first_page= ' home ';

$this->last_page= ' last ';

return $this->first_page (). $this->pre_page (). ' [No. $this->nowindex] '. $this->next_page (). $this->last_page (). ' Section '. $this->select (). ' Page ';

Break

Case ' 3 ':

$this->next_page= ' next page ';

$this->pre_page= ' previous page ';

$this->first_page= ' home ';

$this->last_page= ' last ';

return $this->first_page ("Page_box"). "". $this->pre_page ("Page_box"). "". $this->nowbar ("Page_box_a", "Page_box_b"). "". $this->next_page ("Page_box"). "". $this->last_page ("Page_box"). "";

Break

Case ' 4 ':

$this->next_page= ' next page ';

$this->pre_page= ' previous page ';

return $this->pre_page (). $this->nowbar (). $this->next_page ();

Break

Case ' 5 ':

return $this->pre_bar (). $this->pre_page (). $this->nowbar (). $this->next_page (). $this->next_bar ();

Break

}

}

function _set_url ($url = "")

{

if (!empty ($url)) {

$this->url= $url. (Stristr ($url, '? '))? ' & ': '? '). $this->page_name. " =";

}else{

if (Empty ($_server[' query_string ')) {

$this->url=$_server[' Request_uri ']. "?". $this->page_name. " =";

}else{

if (Stristr ($_server[' query_string '), $this->page_name. ' =')){

$this->url=str_replace ($this->page_name. ' = '. $this->nowindex, ' ', $_server[' Request_uri ']);

$last = $this->url[strlen ($this->url)-1];

if ($last = = '? ' | | $last = = ' & ') {

$this->url.= $this->page_name. " =";

}else{

$this->url.= ' & $this->page_name. " =";

}

}else{

$this->url=$_server[' Request_uri ']. ' & '. $this->page_name. ' =';

}

}

}

}


function _set_nowindex ($nowindex)

{

if (empty ($nowindex)) {

if (Isset ($_get[$this->page_name])) {

$this->nowindex=intval ($_get[$this->page_name]);

}

}else{

$this->nowindex=intval ($nowindex);

}

}

function _get_url ($pageno =1)
{
Global $_cfg;
$arr = $this->rewrite;
Print_r ($arr);
Print_r ($this->url. $pageno);
if ($_cfg[' Urlrewrite ') &&!empty ($arr [' action ']) {
return Url_rewrite ($arr [' action '], array (' id0 ' = = $arr [' id0 '], ' id1 ' + $arr [' id1 '], ' id2 ' = $arr [' Id2 '], ' ID3 ' = = $arr [' ID3 '], ' page ' = $pageno));
}else{
Return $this->url. $pageno;
}

}

function _get_text ($STR)

{

Return $this->format_left. $str. $this->format_right;

}

function _get_link ($url, $text, $style = ") {

$style = (Empty ($style))? ": ' class=" '. $style. ' ";

Return '. $text. ';

}


Function error ($function, $errormsg)

{

Die (' Error in File '. __file__ ' , Function '. $function. ' () : '. $errormsg);

}

}
?>


http://www.bkjia.com/PHPjc/444853.html www.bkjia.com true http://www.bkjia.com/PHPjc/444853.html techarticle PHP Classic Pagination code class This is a PHP page code is a classic can automatically determine the URL parameters and then pagination of the instance code, and customize the page, next page, home, Last Oh, ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.