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 the Code code 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. = "";
$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. = "";
$str. = "> Next page";
return $str;
}
Public Function Getjumppage ()
{
if ($this->is_post)
{
$str = "Skip to Page $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 ();
*/
?>
The above describes the Photoshop CS5 official Chinese official version of the original download PHP page extension code, including the official Chinese version of the original Photoshop cs5 download content, I hope to be interested in PHP tutorial friends helpful.