<?
//分页控制类
//宇凡 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>";
}}
?>
//分页控制类
//宇凡 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>";
}}
?>
解决方案 »
- 关于javascript日历选择的问题
- php-5.2.17 没有VC9版,我怎么才能在iis上安装php?
- Eclipse下php保存后没有实时的预览
- 为什么在ajax中设置cookies会无效的?
- 关于判断uchome 应用失效
- php怎样实现“增加一行 ”“删除一行”行里面有select和text和图片,然后批量保存
- 昨天刚装了PHP5+apache2的环境,其他都正常,但无法修改apache2的主目录
- (散分)smarty模板目录结构与路径问题的解决与探讨!
- mssql_result取数据库varchar的字段时为何有字数限制?
- 在PHP中,如何传递参数,关于下拉列表框的问题!在线等待
- 路径问题:请看下面代吗?
- php为什么不执行???
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();
?>
select * from mytable limit jd,dbcount
'jd为查询开始的记录数,dbcount为要读出的数据数量
通过循环:jd=jd+dbcount