请问如何实现分页处理,包括首页,下一页,上一页,末页,跳转。提一下思路!谢了

hellophp 2001-08-18 01:14:44
加精
请问如何实现分页处理,包括首页,下一页,上一页,末页,跳转。提一下思路!谢了
...全文
503 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
c_crazyren 2001-09-05
  • 打赏
  • 举报
回复
呵呵,也是,我就是没好习惯,怎么不想想把这个写成class,也不用老去在要分也的页面加代码了
lazywolf 2001-08-19
  • 打赏
  • 举报
回复
利用mysql的查询语句来进行:
select * from mytable limit jd,dbcount
'jd为查询开始的记录数,dbcount为要读出的数据数量
通过循环:jd=jd+dbcount
hellophp 2001-08-19
  • 打赏
  • 举报
回复
谢谢了,小弟给分!
zxyufan 2001-08-18
  • 打赏
  • 举报
回复
<?
require("inc/PageControl.inc");

for ($i=0;$i<95;$i++)
{
$int[$i]=$i*$i-$i;
}
$aCtrl = new PageControl($int,$p);
/*echo "总页数 ";
echo $aCtrl->PageAmount;
echo "<br>";
echo "总记录数 ";
echo $aCtrl->RecordAmount;
echo "<br>";
echo "当前页码 ";
echo $aCtrl->Page;
echo "<br>";
echo "下一页的页码 ";
echo $aCtrl->NextPage;
echo "<br>";
echo "上一页的页码 ";
echo $aCtrl->PriorPage;
echo "<br>";
echo "该页显示的起始位置的索引 ";
echo $aCtrl->StartIndex;
echo "<br>";
echo "<br>";
echo "<br>";*/

echo "<font size=2>共有<font color=f24f00>".$aCtrl->RecordAmount."</font>条记录 <font color=f24f00>".$aCtrl->Page."</font>/".$aCtrl->PageAmount."<br><br>";


while ($aCtrl->next_record())
{
$UsingIndex=$aCtrl->UsingIndex+1;
echo "第<font color=f24f00>".$UsingIndex."</font>条记录: ";
echo "<font color=f24f00>".$aCtrl->get()."</font>";
echo "<br>";
}
echo "<br>";
$aCtrl->show_FirstLink();
$aCtrl->show_PriorLink();
$aCtrl->show_NextLink();
$aCtrl->show_LastLink();
$aCtrl->show_JumpForm();
?>
zxyufan 2001-08-18
  • 打赏
  • 举报
回复
以上是分页控制类
以下是实现的例子
zxyufan 2001-08-18
  • 打赏
  • 举报
回复
<?
//分页控制类
//宇凡 8月15日
?>
<?
class PageControl
{
var $PageAmount; //总页数
var $RecordAmount; //总记录数
var $Page; //当前页码
var $RecordRow_Per_aPage = 10; //每页显示的记录条数,事先预定,不通过程序更改
var $NextPage; //下一页的页码
var $PriorPage; //上一页的页码
var $StartIndex; //相当于每页显示的起始位置的索引
var $UsingIndex; //当前使用的数据的索引
var $arrIDList; //保存ID的数组

function pagecontrol($IDList,$PageNow)
{
if (($PageNow == "") || (round($PageNow) == 0))
{
$PageNow=1;
}
$this->arrIDList = $IDList;
$this->Page = $PageNow;
$this->RecordAmount = count($IDList);

if ($this->RecordAmount % $this->RecordRow_Per_aPage == 0) {
$this->PageAmount = $this->RecordAmount / $this->RecordRow_Per_aPage;
} else {
$this->PageAmount = round($this->RecordAmount / $this->RecordRow_Per_aPage);
}

$this->StartIndex = ($this->Page - 1) * $this->RecordRow_Per_aPage;
$this->UsingIndex = $this->StartIndex - 1; //这里减一的目的:得到数据的普遍方法是先Next()再Get数据,比如数据集.

if ($this->Page != $this->PageAmount) {
$this->NextPage = $this->Page + 1;
} else {
$this->NextPage = $this->PageAmount;
}

if ($this->Page != 1) {
$this->PriorPage = $this->Page - 1;
} else {
$this->PriorPage = 1;
}
}

function next_record()
{
$result = false;
if (($this->UsingIndex != $this->RecordAmount - 1) && ($this->UsingIndex - $this->StartIndex < 9)) {
$this->UsingIndex += 1;
$result = true;
} else {
$result = false;
}
return $result;
}

function get()
{
$result = $this->arrIDList[$this->UsingIndex];
return $result;
}

function show_FirstLink()
{
echo " <a href=".$PHP_SELF."?p=1>最前页</a> ";
}

function show_PriorLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->PriorPage.">上一页</a> ";
}

function show_NextLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->NextPage.">下一页</a> ";
}

function show_LastLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->PageAmount.">最后页</a> ";
}

function show_JumpForm()
{
echo "<FORM METHOD=POST ACTION=".$PHP_SELF.">直接到<INPUT TYPE=text NAME=p size=2 class=input>页 <INPUT TYPE=submit value=GOGOGO class=bottem></FORM>";
}

}
?>

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧