色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP 翻頁 實(shí)例代碼

復(fù)制代碼 代碼如下:
<?php
class Page
{
private $pageSize;//每一頁多少行
private $absolutePage;//當(dāng)前頁
private $pageCount;//總頁碼數(shù)
private $totalNum;//總行數(shù)
private $prePage;//
private $nextPage; //
private $sqlStr;
private $baseUrl; //不帶GET參數(shù)的URL get傳輸網(wǎng)址
function __construct($pagesize,$absolutepage,$baseurl,$sqlStr)
{
$this->absolutePage = $absolutepage;
$this->pageSize = $pagesize;
$this->baseUrl = $baseurl;
$this->sqlStr = $sqlStr;
}
//顯示主體內(nèi)容
public function listinfo()
{
$result = DBHelper::ExecuteCommand($this->sqlStr);
// $result = mysql_query($this->sqlStr,$conn);
$this->totalNum = mysql_num_rows($result);//取處結(jié)果集的所有行數(shù)
$this->pageCount = (int)(($this->totalNum -1)/$this->pageSize)+1; //計(jì)算出一共有多少頁
if($this->absolutePage == "" || !is_numeric($this->absolutePage))//如果是頁面第一次加載那么absolutePage的值一定是空的這時(shí)我們認(rèn)為用戶是第一次訪問就給他看第一頁(當(dāng)然你如果想給他看第5頁也可以)
{
$this->absolutePage = 1;//給他看第一頁
}
if($this->absolutePage > $this->pageCount)//如果請(qǐng)求的的頁碼超過了總頁數(shù)我們就顯示最后一頁
{
$this->absolutePage = $this->pageCount;//顯示最后一頁
}
if ($this->totalNum > 1 && $this->absolutePage > 1) //如果滿足顯示的條件我們就讓的頁碼變量的值等于當(dāng)前頁(absolutePage)減一
{
$this->prePage = $this->absolutePage -1;
}
if($this->absolutePage >= 1 && $this->absolutePage < $this->pageCount)//在當(dāng)前頁至少是1并且不大于總頁數(shù)時(shí)給變量賦值為當(dāng)前頁加1
{
$this->nextPage = $this->absolutePage + 1;
}
if (mysql_data_seek($result,($this->absolutePage -1) * $this->pageSize))//決定從結(jié)果集的哪個(gè)位置開始檢索數(shù)據(jù)//決定從結(jié)果集的哪個(gè)位置開始檢索數(shù)據(jù) mysql_data_seek指向下一行
{
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替換兩個(gè)數(shù)組 第二個(gè)替換第一個(gè)數(shù)組,$goodsContent參數(shù)是要替換的對(duì)象
$cishu++;
echo $items;
if ($cishu % 4 == 0)
{
?>
</tr><tr>
<?php
}
}
}
}
}
//分頁動(dòng)作函數(shù)
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;
}
}
?>

php技術(shù)PHP 翻頁 實(shí)例代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 弋阳县| 黄大仙区| 珲春市| 普兰店市| 惠水县| 合肥市| 堆龙德庆县| 论坛| 渭南市| 南皮县| 梓潼县| 望奎县| 普陀区| 安国市| 新宾| 额尔古纳市| 田林县| 霍邱县| 潢川县| 金寨县| 临朐县| 仙桃市| 庆阳市| 新蔡县| 锡林浩特市| 永平县| 富裕县| 田阳县| 江孜县| 荃湾区| 桑植县| 从化市| 郁南县| 西乌| 类乌齐县| 察雅县| 饶阳县| 万载县| 正安县| 高台县| 益阳市|