一个简单的php分页类代码(转载)
入门级php分页类
- 原文地址:http://www.xfcodes.com/php/fenye/3608.htm
- 时间:2015-12-16 20:52:00来源:网络
<?php
/*
* 快速php分页类
*
**/
class Page{
private $totalpage;
private $stride;
private $currentpage;
//设置总页数
function setTotalpage($objpage=1){
$this->totalpage=$objpage;
}
//设置当前页
function setCurrentpage($objpage=1){
$this->currentpage=$objpage;
} //先锋教程网 www.xfcodes.com
//设置跨度
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为主类。可进行分页的创建,修改,显示
*/
?>
一个简单的php分页类代码(转载)的更多相关文章
- 一个简单的CI分页类
[php] view plaincopy <span style="font-size:16px;">/** * * 关于 页码有效性的判断需要加在 控制器中判断,即当 ...
- PHP分页类代码
今天为大家献上一段代码,这是一段php分页代码: <?php//创建分页类class Page { private $_all_num; ...
- php分页类代码带分页样式效果(转)
php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...
- Linux内核分析—完成一个简单的时间片轮转多道程序内核代码
---恢复内容开始--- 20135125陈智威 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10 ...
- 20135202闫佳歆--week2 一个简单的时间片轮转多道程序内核代码及分析
一个简单的时间片轮转多道程序内核代码及分析 所用代码为课程配套git库中下载得到的. 一.进程的启动 /*出自mymain.c*/ /* start process 0 by task[0] */ p ...
- 简单的beego分页功能代码
一个简单的beego分页小插件(源代码在最下面): 支持条件查询 支持参数保留 支持自定义css样式 支持表/视图 支持参数自定义 默认为pno 支持定义生成链接的个数 使用方式: 1)action中 ...
- python定义的一个简单的shell函数的代码
把写代码过程中经常用到的一些代码段做个记录,如下代码段是关于python定义的一个简单的shell函数的代码. pipe = subprocess.Popen(cmd, stdout=subproce ...
- php分页类代码和使用
在这要说的一点就是如果你做的分页是有搜索条件的,那么就可以用下面的代码,然后调用之后在new Page()里面把连接加进去就可以了.例如: $href="http://www.***.cn/ ...
- Linux内核分析:完成一个简单的时间片轮转多道程序内核代码
PS.贺邦 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 1.m ...
随机推荐
- Hibernate - 使用注解完成映射
除了使用XML配置来映射对象和数据库表,还可以使用注解来完成持久化.使用注解需要导入Hibernate Annotations扩展包 @Entity -加在类的前面,将类声明为持久化类. -javax ...
- HTTPS证书制作
openssl 安装可参照之前文章 1.mkdir /etc/ssl/xip.ioopenssl genrsa -out /etc/ssl/xip.io/xip.io.key 1024openssl ...
- jquery用on代替bind(),live(),delegate()的方法
Js的功能确实非常强大,奈何我一个php程序员一直在js上没有投入足够的精力去研究,每次遇到不会的都是去百度,以后有时间真的应该买本书系统的学习一下 // Bind $( "#members ...
- 【二分答案+贪心】解决“最小值最大”问题(UVa 12124 - Assemble)
Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to p ...
- PHP 点滴疑惑
在数据库中,字段为NULL,可以使用empty()进行判断 <?php $CONFIG['hostname'] = 'localhost'; $CONFIG['username'] = 'roo ...
- 在重命名SqlServer数据库是,报5030错误的解决办法
数据库不能重名名5030的错误,其实很简单原因就是有应用程序正在占用这个连接,使用这样一行命令就可以查询出正在占用的连接 use master select spid from master.dbo. ...
- JavaScript高级程序设计(第三版)学习笔记6、7章
第6章,面向对象的程序设计 对象: 1.数据属性 configurable,表示能否通过delete删除属性从而重新定义属性,能否修改属性的特性,或能否把属性修改为访问器属性,默认为true en ...
- Android IntentService使用
因为多数启动服务不必同时处理多个请求(在多线程情景下会很危险),所以使用IntentService类实现服务是很好的选择.本经验将通过继承IntentService输出当前时间教大家如何使用Inten ...
- php正则贪婪匹配与非贪婪匹配一些例子
http://www.111cn.net/phper/210/55600.htm 贪婪模式匹配的原则是: 在可匹配也可不匹配的情况下, 优先匹配,直到不能匹配成功的情况下,记录备选状态,并把匹配控制交 ...
- 经历:easyui的layout自适应高度布局
在使用easyui的layout布局的时候,在某种情况下,我们会在后续的逻辑中修改一下layout的某个region的高度,那么该怎么做呢? 我就遇到了这样的情况,今天需求经理提出了一个需求:认证用 ...