快速好用的php分页类
2013-11-04 00:00
369 查看
发布:thebaby 来源:net 【大 中 小】
一个快速好用的php分页类,有需要的朋友,可以参考下。
php分页类。
<?php
/*
* 快速php分页类
*
**/
class Page{
private $totalpage;
private $stride;
private $currentpage;
//设置总页数
function setTotalpage($objpage=1){
$this->totalpage=$objpage;
}
//设置当前页
function setCurrentpage($objpage=1){
$this->currentpage=$objpage;
}
//设置跨度
function setStride($objStride=1){
$this->stride=$objStride;
}
//获得总页数
function getTotalpage(){
return $this->totalpage;
}
//获得跨读
function getStride($objStride=1){
return $this->stride;
}
//获取当前页
function getCurrentpage($objpage=1){
return $this->currentpage;
}
//打印分页
public function Pageprint(){
for($Tmpa=1;$Tmpa<=$this->totalpage;$Tmpa++){
if($Tmpa+$this->stride<$this->currentpage){//加了跨度还小于当前页的不显示
continue;
}
if($Tmpa+$this->stride==$this->currentpage){//刚好够跨度的页数
$p=$this->currentpage-1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=1\"><span>首页</span></a> <a href=\"$_SERVER[PHP_SELF]?page=$p\"><span>上一页</span></a> ";
}
if($Tmpa>$this->currentpage+$this->stride){//大于当前页+跨度的页面
break;
}
$willprint.="[<span><a href=\"$_SERVER[PHP_SELF]?page=$Tmpa\">$Tmpa</a></span>]";
if($Tmpa==$this->currentpage+$this->stride){//刚好够跨度的页数
$p=$this->currentpage+$this->stride+1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$p\"><span>下一页</span></a> <a href=\"$_SERVER[PHP_SELF]?page=$this->totalpage\"><span>末页</span></a>";
}
}
echo $willprint;
}
}
class cut_page extends Page
{
var $filename;
var $showtotal;
function __construct($filename){
$this->cachefile = $filename;
$this->showtotal = "yes";
}
public function filename(){
if (file_exists($this->cachefile)){
return 1;
}
else
return 0;
}
private $type;
public function typelist($typeid){
$this->type = $typeid;
$fp = fopen($this->cachefile,"rb");
$str= fread($fp,filesize($this->cachefile));
//echo $this->type."<br>"; //分类ID
$arr= explode()("::",$str);
for ($i=0;$i<count($arr);$i++){
$arr2 = explode("=",$arr[$i]);
if($arr2[0]==$this->type){
//return $arr2[1];
if(isset()($_GET[page])){
$page=$_GET[page];
}else{
$page=1;
}
Page::setTotalpage($arr2[1]);
Page::setCurrentpage($page);
Page::setStride(3);
Page::Pageprint();
if ($this->showtotal=="yes"){
echo "<span style=\"border:1px solid #ccc;margin-left:40px;padding:1px 1px;\">".$page."/".$arr2[1]."页</span>";
}
}
}
fclose($fp);
}
public function updatelist($typeid,$value){
$this->type = $typeid;
$this->typevalue=$value;
if (file_exists($this->cachefile)){ //若文件存在
$fp = fopen($this->cachefile,"rb+");
$str= fread($fp,filesize($this->cachefile));
if(ereg("::".$this->type."=[0-9]+",$str)){
//正则替换
$str2= ereg_replace("::".$this->type."=[0-9]+","::".$this->type."=".$this->typevalue,$str);
fseek($fp,0); //从文件头开始
fwrite($fp,$str2); //写入文件新数据
$seek = ftell($fp); //返回文件指针长度
ftruncate($fp,$seek); //截断文件
}
else{
$str2 = "::".$this->type."=".$this->typevalue;
fwrite($fp,$str2); //若分类ID不存在,则续写文件
}
}
else{ //若文件不存在
$fp = fopen($this->cachefile,"xb");
$str="::".$this->type."=".$this->typevalue;
fwrite($fp,$str);
}
fclose($fp);
}
}
/*使用方法,参数为缓存文件名,可自定义*/
$listpage = new cut_page("pages_cache.txt");
/*列出分页 参数为分类的ID*/
$listpage->typelist("2");
$listpage->showtotal="yes"; //是否显示总数yes /no 默认为yes
echo "<br>";
/*
修改分页文件或者创建分页文件,参数分别为分类ID,分页数量,此方法使用在创建文章后遍历数据库获得分类的ID及分页的总量
分页=总记录/每页显示数目 ^0^这个自己算。updatelist(type,num)
//$listpage->updatelist("6","900");
cut_page为主类。可进行分页的创建,修改,显示
*/
?>
本文原始链接:http://www.jbxue.com/article/3608.html
一个快速好用的php分页类,有需要的朋友,可以参考下。
php分页类。
<?php
/*
* 快速php分页类
*
**/
class Page{
private $totalpage;
private $stride;
private $currentpage;
//设置总页数
function setTotalpage($objpage=1){
$this->totalpage=$objpage;
}
//设置当前页
function setCurrentpage($objpage=1){
$this->currentpage=$objpage;
}
//设置跨度
function setStride($objStride=1){
$this->stride=$objStride;
}
//获得总页数
function getTotalpage(){
return $this->totalpage;
}
//获得跨读
function getStride($objStride=1){
return $this->stride;
}
//获取当前页
function getCurrentpage($objpage=1){
return $this->currentpage;
}
//打印分页
public function Pageprint(){
for($Tmpa=1;$Tmpa<=$this->totalpage;$Tmpa++){
if($Tmpa+$this->stride<$this->currentpage){//加了跨度还小于当前页的不显示
continue;
}
if($Tmpa+$this->stride==$this->currentpage){//刚好够跨度的页数
$p=$this->currentpage-1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=1\"><span>首页</span></a> <a href=\"$_SERVER[PHP_SELF]?page=$p\"><span>上一页</span></a> ";
}
if($Tmpa>$this->currentpage+$this->stride){//大于当前页+跨度的页面
break;
}
$willprint.="[<span><a href=\"$_SERVER[PHP_SELF]?page=$Tmpa\">$Tmpa</a></span>]";
if($Tmpa==$this->currentpage+$this->stride){//刚好够跨度的页数
$p=$this->currentpage+$this->stride+1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$p\"><span>下一页</span></a> <a href=\"$_SERVER[PHP_SELF]?page=$this->totalpage\"><span>末页</span></a>";
}
}
echo $willprint;
}
}
class cut_page extends Page
{
var $filename;
var $showtotal;
function __construct($filename){
$this->cachefile = $filename;
$this->showtotal = "yes";
}
public function filename(){
if (file_exists($this->cachefile)){
return 1;
}
else
return 0;
}
private $type;
public function typelist($typeid){
$this->type = $typeid;
$fp = fopen($this->cachefile,"rb");
$str= fread($fp,filesize($this->cachefile));
//echo $this->type."<br>"; //分类ID
$arr= explode()("::",$str);
for ($i=0;$i<count($arr);$i++){
$arr2 = explode("=",$arr[$i]);
if($arr2[0]==$this->type){
//return $arr2[1];
if(isset()($_GET[page])){
$page=$_GET[page];
}else{
$page=1;
}
Page::setTotalpage($arr2[1]);
Page::setCurrentpage($page);
Page::setStride(3);
Page::Pageprint();
if ($this->showtotal=="yes"){
echo "<span style=\"border:1px solid #ccc;margin-left:40px;padding:1px 1px;\">".$page."/".$arr2[1]."页</span>";
}
}
}
fclose($fp);
}
public function updatelist($typeid,$value){
$this->type = $typeid;
$this->typevalue=$value;
if (file_exists($this->cachefile)){ //若文件存在
$fp = fopen($this->cachefile,"rb+");
$str= fread($fp,filesize($this->cachefile));
if(ereg("::".$this->type."=[0-9]+",$str)){
//正则替换
$str2= ereg_replace("::".$this->type."=[0-9]+","::".$this->type."=".$this->typevalue,$str);
fseek($fp,0); //从文件头开始
fwrite($fp,$str2); //写入文件新数据
$seek = ftell($fp); //返回文件指针长度
ftruncate($fp,$seek); //截断文件
}
else{
$str2 = "::".$this->type."=".$this->typevalue;
fwrite($fp,$str2); //若分类ID不存在,则续写文件
}
}
else{ //若文件不存在
$fp = fopen($this->cachefile,"xb");
$str="::".$this->type."=".$this->typevalue;
fwrite($fp,$str);
}
fclose($fp);
}
}
/*使用方法,参数为缓存文件名,可自定义*/
$listpage = new cut_page("pages_cache.txt");
/*列出分页 参数为分类的ID*/
$listpage->typelist("2");
$listpage->showtotal="yes"; //是否显示总数yes /no 默认为yes
echo "<br>";
/*
修改分页文件或者创建分页文件,参数分别为分类ID,分页数量,此方法使用在创建文章后遍历数据库获得分类的ID及分页的总量
分页=总记录/每页显示数目 ^0^这个自己算。updatelist(type,num)
//$listpage->updatelist("6","900");
cut_page为主类。可进行分页的创建,修改,显示
*/
?>
本文原始链接:http://www.jbxue.com/article/3608.html
相关文章推荐
- 使用PHP 快速生成Flash 动画
- php实现cc攻击防御和防止快速刷新页面示例
- 关于php内存不够用的快速解决方法
- 快速搭建Web服务器软件PHP+Apache+MySQL
- Sublime Text3快速编译php
- 快速开发一个PHP扩展
- Win7、windows 2008 IIS7.5下载安装方法以及教程 IIS7配置PHP环境图文教程(fastcgi快速最新版)
- linux下快速安装apache+php+mysql
- php漂亮的分页类
- PHP定界符快速上手
- PHP快速入门教程:服务器和浏览器变量获取示例
- PHP导出EXCEL快速开发指南--PHPEXCEL的使用详解
- 分享一个PHP数据库分页类
- PHP正则表达式的快速学习方法
- php面试算法题—快速算法、冒泡算法讲解
- php分页类,只需3句话就搞定了,值得收藏,挺好用的。
- 快速搭建 php +myspl +apacheh环境下载
- PHP快速按行读取CSV大文件的封装类分享(也适用于其它超大文本文件)
- php分页类
- CentOs 通过yum快速搭建LAMP记载, 并将php升级到5.3