Copy CodeThe code is as follows:
Class Page
{
private $pageSize;//How many rows per page
private $absolutePage;//Current page
private $pageCount;//Total page number
private $totalNum;//Total number of rows
private $prePage;//Previous Page
Private $nextPage; Next page
Private $sqlStr;
Private $BASEURL; URL get transfer URL without get parameter
function __construct ($pagesize, $absolutepage, $baseurl, $SQLSTR)
{
$this->absolutepage = $absolutepage;
$this->pagesize = $pagesize;
$this->baseurl = $baseurl;
$this->sqlstr = $sqlStr;
}
Show Body Content
Public Function Listinfo ()
{
$result = Dbhelper::executecommand ($this->sqlstr);
$result = mysql_query ($this->sqlstr, $conn);
$this->totalnum = mysql_num_rows ($result);//Fetch all rows of the result set
$this->pagecount = (int) (($this->totalnum-1)/$this->pagesize) +1; Calculate the total number of pages
if ($this->absolutepage = = "" | |! Is_numeric ($this->absolutepage))//If it is the first time the page is loaded then the value of AbsolutePage must be empty at this point we think the user is the first visit to show him the first page (of course, if you want to show him the 5th page can also)
{
$this->absolutepage = 1;//show him the first page
}
if ($this->absolutepage > $this->pagecount)//If the page number on the next page of the request exceeds the total page count, we'll show the last one.
{
$this->absolutepage = $this->pagecount;//Show last page
}
if ($this->totalnum > 1 && $this->absolutepage > 1)//If the conditions of the previous page are met we let the page number of the previous pages variable value equals the current page (AbsolutePage ) Minus One
{
$this->prepage = $this->absolutepage-1;
}
if ($this->absolutepage >= 1 && $this->absolutepage < $this->pagecount)// Assigns the next page variable to the current page plus 1 when the current page is at least 1 and is not greater than the total number of pages
{
$this->nextpage = $this->absolutepage + 1;
}
if (Mysql_data_seek ($result, ($this->absolutepage-1) * $this->pagesize))//decide where to start retrieving data from the result set// Decide where to start retrieving data from the result set Mysql_data_seek point to the next line
{
Include ("goodstemplate.php");
for ($i = 0; $i < $this->pagesize; $i + +)
{
if ($info = mysql_fetch_array ($result)))
{
$name = $info [' Goodsname '];
$tupian = $info [' Goodsphopo '];
$id = $info [' Goodsid '];
$price = $info [' Goodsprice '];
$url = ' detail.php?id= '. $id;
$items = str_replace (Array (' {name} ', ' {Tupian} ', ' {URL} ', ' {price} ', ' {ID} '), Array ($name, $tupian, $url, $price, $id), $ goodscontent);//str_replace Replace two array the second replaces the first array, $goodsContent parameter is the object to replace
$cishu + +;
Echo $items;
if ($cishu% 4 = = 0)
{
?>
}
}
}
}
}
Paging Action function
Public Function ToPage ()
{
Include (' topagetemplate.php ');
if ($this->totalnum > 1 && $this->absolutepage > 1)
{
$this->prepage = $this->absolutepage-1;
}
if ($this->absolutepage >= 1 && $this->absolutepage < $this->pagecount)
{
$this->nextpage = $this->absolutepage + 1;
}
$PREURL = $this->baseurl. "? absolutepage= $this->prepage ";
$NEXTURL = $this->baseurl. "? absolutepage= $this->nextpage ";
$items = str_replace (Array (' {totalnum} ', ' {absolutepage} ', ' {PageCount} ', ' {preUrl} ', ' {nexturl} '), Array ($this- Totalnum, $this->absolutepage, $this->pagecount, $preUrl, $NEXTURL), $toPage);
Echo $items;
}
}
?>
http://www.bkjia.com/PHPjc/320414.html www.bkjia.com true http://www.bkjia.com/PHPjc/320414.html techarticle Copy the code as follows: PHP class page {private $pageSize;//number of rows per page private $absolutePage;//current page private $pageCount;//Total page number private $totalNum;//Total number of rows ...