欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【PHP实例源代码:PHP实现翻页处理的类】,下面是详细的分享!
PHP实例源代码:PHP实现翻页处理的类
<?php
class Page{
var $CountAll; //共有纪录数
var $CountPage; //每页显示记录数
var $Link; //显示 完整的分页信息
var $ForPage; //上一页
var $NextPage; //下一页
var $FirstPage; //第一页
var $LastPage; //最后一页
var $CurrPage; //第几页
var $PageNum; //共有多少页
var $Parameter; //参数
var $LimitNum; //不是统计全部记录,而是显示部分记录,例如共有100条记录,但是只统计显示前50条
function Page($sql, $num=30){
//初始化,统计记录数
$this->CountPage=$num;
global $mysql;
$sql=base64_decode($sql);
$result=$mysql->Query($sql);
if (0 !=$mysql->AffectedRows()){
$row=$mysql->FetchArray($result);
$this->CountAll=$row[0];
}
else{
$this->CountAll=0;
}
//print "共有 $this->CountAll <br>";
}
function ListPage($sql, $page=0,$sql_all,$other){
//查询,定义变量,获取数据
global $mysql;
//print "sql sql<br>";
if (isset($this->LimitNum) && $this->CountAll > $this->LimitNum){
$this->CountAll=$this->LimitNum;
}//更新总浏览记录数
$sql_src=http://www.chinaz.com/program/2007/1008/$sql;
//if ($page > 0){
$sql=base64_decode($sql);
$sql_all=base64_decode($sql_all);
$sql_src=http://www.chinaz.com/program/2007/1008/$sql;
//}
//echo $sql;
if (($this->CountAll % $this->CountPage)==0)//统计共有多少页
$pagecount=(integer)($this->CountAll/$this->CountPage);
else
$pagecount=(integer)($this->CountAll/$this->CountPage)+1;
$this->ageNum=$pagecount;
if ($page > $this->ageNum)//如果页码超过页码总数则设为最大页码
$page=$this->ageNum;
if ($page <=0)//如果页码小于等于零则将页码设置为1
$page=1;
if ($this->CountAll==0)
{
$this->CurrPage=0;
}else{
$this->CurrPage=$page;
}
$first_start=($page-1)*$this->CountPage;
$sql=$sql." limit ".$first_start.", ".$this->CountPage;
//print "2sql<br>";
$result=$mysql->Query($sql);
if (0 !=$mysql->AffectedRows()){
$i=0;
while($row=$mysql->FetchArray($result)){
$array[$i]=$row;
//print "name:".$array[$i][Name]."<br>";
$i++;
}
}
$sql=base64_encode($sql_src);
$sql_all=base64_encode($sql_all);
if ($pagecount >1){
if($page==1){
$nextpage=$page+1;
$forpage=1;
$this->Link="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$nextpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/next.gif" align="absmiddle"> </button><button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$pagecount".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_end.gif" align="absmiddle"> </button>";
$this->NextPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$nextpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/next.gif" align="absmiddle"> </button>";
$this->LastPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$pagecount".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_end.gif" align="absmiddle"> </button>";
}
else if(($page > 1)&&($page < $pagecount)) {
$forpage=$page-1;
$nextpage=$page+1;
$this->Link="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=1".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_top.gif" align="absmiddle"> </button><button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$forpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev.gif" align="absmiddle"> </button><button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$nextpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/next.gif" align="absmiddle"> </button><button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$pagecount".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_end.gif" align="absmiddle"> </button>";
$this->ForPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$forpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev.gif" align="absmiddle"> </button>";
$this->NextPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$nextpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/next.gif" align="absmiddle"> </button>";
$this->FirstPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=1".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_top.gif" align="absmiddle"> </button>";
$this->LastPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$pagecount".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_end.gif" align="absmiddle"> </button>";
}
else if ($page=$pagecount){
$forpage=$page-1;
$nextpage=1;
$this->Link="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=1".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_top.gif" align="absmiddle"> </button><button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$forpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev.gif" align="absmiddle"> </button>";
$this->FirstPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=1".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev_top.gif" align="absmiddle"> </button>";
$this->ForPage="<button onClick="javascript:location.href='http://www.chinaz.com/program/2007/1008/?query_sql=$sql&query_page=$forpage".$this->Parameter."&sql_all=".$sql_all."".$other."'" class="button_a" style="width:30;height:22";><img src=http://www.chinaz.com/program/2007/1008/"images/prev.gif" align="absmiddle"> </button>";
}
}
else{
$this->Link=' ';
}
return $array;//$array;
}
}
?>
以上所分享的是关于PHP实例源代码:PHP实现翻页处理的类,下面是编辑为你推荐的有价值的用户互动:
相关问题:PHP代码实现分页功能、看我下面简单代码
答:$pnum=$totalNum/$pageSize 改成 $pnum=ceil($totalNum/$pageSize); 后面加 >>详细
相关问题:用php代码实现 文件操作类题目!!
答:Web开发是今后分布式程式开发的主流,通常的web开发都要涉及到与数据库打交道,客户端从服务器端读取通常都是以分页的形式来显示,一页一页的阅读起来既方便又美观。所以说写分页程序是web开发的一个重要组成部分,在这里,我们共同来研究分页程... >>详细
相关问题:php分页代码 怎么写
答: 清华潘恩华出的,我感觉挺好,沈阳图书馆半个会员就能免费借,不知道你那里能不能 >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
