PHP Paging Class extension Code _php Tutorial

Source: Internet
Author: User
Originally published a Break out of the Database page class, recently used to find some time to search for something too large, the use of URL to pass parameters, there may be some impact or known bugs, this time to do some expansion, and compatible with the previous pattern, using the above is very simple, You just need to set one more parameter to the code as follows:
Copy CodeThe code is as follows:
/**
* Function: Paging class, according to the amount of data provided and page size
* Date Created: Fri Apr 16:45:21 CST 2007
* Last update:
* Author: Sanshi
*/

class pagination
{
var $result = array ();
var $pVar = "MYP";//page parameter page count
var $urlParamStr = ""; All parameters of the page
var $sqlMoveNumber = 0; The offset of the data
var $is _post = false;

Public function pagination ()
{

}
Public function set ($sum, $pageSize, $page = "", $is _post = False)
{
$this->is_post = $is _post;
$this->pvar = defined (' Page_bar ')? Page_bar: ' MYP ';
$url = $_server[' php_self ']. '? '. $_server[' query_string '];
Calculate the total number of pages
$curPage = $this->getcurpage ();

$temp [' sumpage '] = ceil ($sum/$pageSize);
Bug modified, page number exceeded
if ($curPage > $temp [' sumpage ']) $curPage = $temp [' Sumpage '];
$temp [' curpage '] = $curPage;
$temp [' nextPage '] = $temp [' sumpage '] > $curPage? ($curPage + 1): $temp [' sumpage '];
$temp [' uppage '] = $curPage >1? $curPage-1:1;
$temp [' endpage '] = $temp [' Sumpage '];
$this->urlparamstr = $this->_makeurl ($url);
$temp [' urlpagestr '] = ($page = = "")? $this->_makeurl ($url): $page. $this->urlparamstr;

$this->sqlmovenumber = $curPage <2? 0: ($curPage-1) * $pageSize;
$temp [' sqlmovenumber '] = $this->sqlmovenumber;
$temp [' rowNo '] = $sum;
$this->result = $temp;
return $this->result;
Print_r ($temp); exit ();
}
Public Function Getsqlmove ()
{
return $this->sqlmovenumber;
}
Public Function Getfooter ()
{
$STR = "Total {$this->result[' rowNo '}" result[' Urlpagestr ']}{$this->result[' uppage '} ' ";
if ($this->is_post) $str. = "Onclick= ' return Sanshi_page_post (this.href,{$this->result[' Uppage ']}); ' ";
$str. = "> Previous page";
$str. = "Current {$this->result[' curpage '} page";
$str. = "Total {$this->result[' sumpage '} page";
$str. = "result[' urlpagestr ']}{$this->result[' nextPage ']} '";
if ($this->is_post) $str. = "Onclick= ' return Sanshi_page_post (this.href,{$this->result[' NextPage ']}); ' ";
$str. = "> Next page";
return $str;
}
Public Function Getjumppage ()
{
if ($this->is_post)
{
$str = "Skip to Page \ n "; }else{$str = "Jump to Page\ n ";
}
for ($i =1; $i <= $this->result[' sumpage '); $i + +)
{
$str. = ($i = = $this->result[' curpage ')? " $i\ n ":" $i\ n ";
}
$str. = "Page ";
Output Form form
if ($this->is_post)
{
$str. = "";
$str. = "";
}
return $str;
}
Public Function Getcurpage ()
{
return Isset ($_get[$this->pvar])? Intval ($_get[$this->pvar]): 1;
}
Parse out the parameters of the URL to return? After the argument, the page number is empty including the question mark
Private Function _makeurl ($url)
{
$arrayUrl =parse_url ($url);
if (Isset ($arrayUrl [' query ']))
{
$q = $arrayUrl [' query '];
Parse_str ($q, $qParam);
Print_r ($qParam);
if (array_key_exists ($this->pvar, $qParam))
{
foreach ($qParam as $k = $v)
{
if ($k! = $this->pvar) $temp [$k] = $v;
}
$temp [$this->pvar] = "";
if (function_exists ("Http_build_query"))
Return '? '. Http_build_query ($temp);
Else
Return '? '. Sanshi_http_build_query ($temp);
}else {
Return "? {$q}&{$this->pvar}= ";
}
}else{
Return "? {$this->pvar}= ";
}

}
}
function Sanshi_http_build_query ($a, $b = ", $c =0)
{
if (!is_array ($a)) return false;
foreach ((array) $a as $k + = $v)
{
if ($c)
$k = $b. " [". $k."] ";
ElseIf (Is_int ($k))
$k = $b. $k;
if (Is_array ($v) | | Is_object ($v))
{
$r []=http_build_query ($v, $k, 1);
Continue
}
$r []= $k.] = ". UrlEncode ($v);
}
Return implode ("&", $r);
}
/*
Print_r ($_server);
$p = new pagination ();
$p->set (10,2, ' thi.php ');
echo $p->getfooter ();
echo $p->getjumppage ();
*/
?>

http://www.bkjia.com/PHPjc/320231.html www.bkjia.com true http://www.bkjia.com/PHPjc/320231.html techarticle Originally published a Break out of the Database page class, recently used to find some time to search for something too large, the use of the URL to pass parameters, there may be a certain shadow ...

  • 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.