一个简单的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 ...
随机推荐
- [Doc ID 433386.1]JSP Pages Hanging in R12 After Removing Cached Class Files in _pages
In this Document Symptoms Changes Cause Solution References Applies to: Oracle Application ...
- mongodb添加权限
1.连接mongodb数据库(如果mongo命令没有做环境变量配置,需要定位到有mongo命令的目录) root@AY140709212620347s22Z:~# mongo MongoDB shel ...
- Android Dialog(对话框)
一个对话框一般是一个出现在当前Activity之上的一个小窗口. 处于下面的Activity失去焦点, 对话框接受所有的用户交互. 对话框一般用于提示信息和与当前应用程序直接相关的小功能. Andro ...
- NC表型参照类
package nc.ui.bd.ref; /** * 表参照-其他参照基类. 创建日期:(2001-8-23 20:26:54) 模型里未处理栏目 * * @author:张扬 * */ impor ...
- getOutputStream() has already been called for this response异常的原因和解决方法
今天在调试一个小web项目时,验证码不显示了,而且后台报错 getOutputStream() has already been called for this response 经过查找得知: 在t ...
- jenkins离线安装git插件
jenkins没有默认安装git,当jenkins无法连接外网的话,安装git插件就是一件很麻烦的事,需要自己去下载插件: 往下拉 这边的插件就是需要自己去下载了,在bing下搜索jenkins gi ...
- 使用自签SSL证书有什么风险?
http://mt.sohu.com/20150602/n414267586.shtml 所谓自签SSL证书,是指不受信任的任意机构或个人,使用工具自己签发的SSL证书.自签名SSL证书可以随意签发, ...
- OC3_字符串分割
// // main.m // OC3_字符串分割 // // Created by zhangxueming on 15/6/11. // Copyright (c) 2015年 zhangxuem ...
- Oracle PL/SQL 找出100以内是3和5的倍数的数 循环语句
循环: loop --执行代码 exit when 表达式;--当表达式为真退出循环.(注意,其编写位置决定循环为先判断还是先执行,相当于java的while或do-while) end loop; ...
- 用Python进行语音信号处理
1.语音信号处理之时域分析-音高追踪及其Python实现 2.语音信号处理之时域分析-音高及其Python实现 参考: 1.NumPy