PHP Paging class Instance code

Source: Internet
Author: User
PHP Paging Instance code, we can refer to the next.

<?php
Class Page
{
private $pageSize;//How many lines per page
Private $absolutePage//Current page
private $pageCount;//Total number of pages
Private $totalNum//Total rows
private $prePage;//Previous Page
Private $nextPage; Next page
Private $sqlStr;
Private $BASEURL; URL Get transfer web address without got 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; Figure out how many pages there are
if ($this->absolutepage = ""!is_numeric ($this->absolutepage))// If the page is first loaded then the AbsolutePage value must be empty at this time we think that the user is the first visit to show him the first page (of course, if you want to show him page 5th can also)
{
$this->absolutepage = 1;//show him the first page
}
if ($this->absolutepage > $this->pagecount)//If the next page of the request exceeds the total number of pages, we will display the last page.
{
$this->absolutepage = $this->pagecount;//Display last page
}
if ($this->totalnum > 1 && $this->absolutepage > 1)//If the conditions for displaying the previous page are met we'll let the page number variable's value equal to 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 ($result, ($this->absolutepage-1) * $this->pagesize)//determines where to start retrieving data from the result set (Mysql_data_seek)// 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 replaces two arrays the second replaces the first array, $goodsContent parameter is the object to replace
$cishu + +;
Echo $items;
if ($cishu% 4 = 0)
{
?>
</tr><tr>
<?php
}
}
}
}
}
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;
}
}
?>



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.