偶的分页类,希望老大们指点
时间:2007-03-15
来源:互联网
复制PHP内容到剪贴板
<?php
/**
* @页面:main.class.php
* @功能:主要功能类
* @时间:
*/
####分页类####
class PageList
{
var $m_beginno; //页码起始数
var $m_endno; //页码结尾数
var $m_allno; //页码(数组)
var $m_listno; //页码数
var $m_pcount; //总页数
var $m_cpage; //当前页
var $m_prevpage; //上一页码
var $m_nextpage; //下一页码
var $m_r_count; //总记录数
//构造函数(空间是PHP4的)
function PageList($m_pcount,$m_listno)//
{
global $cpage,$r_count;//当前页,总页数
$this->m_r_count = $r_count[0];
$this->m_listno = $m_listno;
$this->m_pcount = $m_pcount;
$this->m_cpage = $cpage;
$this->m_prevpage = $this->m_cpage<=1 ? 1 : $this->m_cpage-1;
$this->m_nextpage = $this->m_cpage>=$this->m_pcount ? $this->m_pcount : $this->m_cpage+1;
}
/**
* @方法:getNums()
* @功能:生成页码
*/
function getNums()
{
if ( $this->m_pcount>$this->m_listno )
{
if ( $this->m_listno%2 == 1 )
{
$this->m_beginno = $this->m_cpage-($this->m_listno-1)/2;
$this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
$this->m_endno = $this->m_cpage+($this->m_listno-1)/2;
$this->m_endno = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
}
if ( $this->m_listno%2 == 0 )
{
$this->m_beginno = $this->m_cpage-($this->m_listno/2-1);
$this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
$this->m_endno = $this->m_cpage+$this->m_listno/2;
$this->m_endno = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
}
if ( $this->m_endno<$this->m_listno )
{
$this->m_endno = $this->m_endno+($this->m_listno-$this->m_endno);
}
if ( $this->m_endno-$this->m_beginno<$this->m_listno )
{
$this->m_beginno = $this->m_beginno-($this->m_listno-($this->m_endno-$this->m_beginno)-1);
}
}
else
{
$this->m_beginno = 1;
$this->m_endno = $this->m_pcount;
}
for ( $i=$this->m_beginno;$i<=$this->m_endno;$i++ )
{
$this->m_allno[] = $i;
}
return $this->m_allno;
}
/**
* @方法:pageShow()
* @功能:输出页码列表
*/
function pageShow()
{
echo ("<div id=\"pagelist\">\n");
echo ("<ul>\n");
echo ("<span>共{$this->m_r_count}条 第{$this->m_cpage}/{$this->m_pcount}页</span>\n");
echo ("<li><a href=\"index.php?page=1\" title=\"第一页\"><<</a></li><li><a href=\"index.php?page={$this->m_prevpage}\" title=\"上一页\"><</a></li>");
foreach ( $this->m_allno as $value)
{
$url = "<a href=\"index.php?page={$value}\" title=\"第{$value}页\">".$value."</a>";
$url = $value==$this->m_cpage ? "<b>".$value."</b>" : $url;
echo "<li>".$url."</li>\n";
}
echo ("<li><a href=\"index.php?page={$this->m_nextpage}\" title=\"下一页\">></a></li><li><a href=\"index.php?page={$this->m_pcount}\" title=\"最后一页\">>></a></li>");
echo ("</ul>\n");
echo ("</div>\n");
}
}
效果演示:http://www.06web.cn/gbPHP代码:
<?php
/**
* @页面:main.class.php
* @功能:主要功能类
* @时间:
*/
####分页类####
class PageList
{
var $m_beginno; //页码起始数
var $m_endno; //页码结尾数
var $m_allno; //页码(数组)
var $m_listno; //页码数
var $m_pcount; //总页数
var $m_cpage; //当前页
var $m_prevpage; //上一页码
var $m_nextpage; //下一页码
var $m_r_count; //总记录数
//构造函数(空间是PHP4的)
function PageList($m_pcount,$m_listno)//
{
global $cpage,$r_count;//当前页,总页数
$this->m_r_count = $r_count[0];
$this->m_listno = $m_listno;
$this->m_pcount = $m_pcount;
$this->m_cpage = $cpage;
$this->m_prevpage = $this->m_cpage<=1 ? 1 : $this->m_cpage-1;
$this->m_nextpage = $this->m_cpage>=$this->m_pcount ? $this->m_pcount : $this->m_cpage+1;
}
/**
* @方法:getNums()
* @功能:生成页码
*/
function getNums()
{
if ( $this->m_pcount>$this->m_listno )
{
if ( $this->m_listno%2 == 1 )
{
$this->m_beginno = $this->m_cpage-($this->m_listno-1)/2;
$this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
$this->m_endno = $this->m_cpage+($this->m_listno-1)/2;
$this->m_endno = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
}
if ( $this->m_listno%2 == 0 )
{
$this->m_beginno = $this->m_cpage-($this->m_listno/2-1);
$this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
$this->m_endno = $this->m_cpage+$this->m_listno/2;
$this->m_endno = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
}
if ( $this->m_endno<$this->m_listno )
{
$this->m_endno = $this->m_endno+($this->m_listno-$this->m_endno);
}
if ( $this->m_endno-$this->m_beginno<$this->m_listno )
{
$this->m_beginno = $this->m_beginno-($this->m_listno-($this->m_endno-$this->m_beginno)-1);
}
}
else
{
$this->m_beginno = 1;
$this->m_endno = $this->m_pcount;
}
for ( $i=$this->m_beginno;$i<=$this->m_endno;$i++ )
{
$this->m_allno[] = $i;
}
return $this->m_allno;
}
/**
* @方法:pageShow()
* @功能:输出页码列表
*/
function pageShow()
{
echo ("<div id=\"pagelist\">\n");
echo ("<ul>\n");
echo ("<span>共{$this->m_r_count}条 第{$this->m_cpage}/{$this->m_pcount}页</span>\n");
echo ("<li><a href=\"index.php?page=1\" title=\"第一页\"><<</a></li><li><a href=\"index.php?page={$this->m_prevpage}\" title=\"上一页\"><</a></li>");
foreach ( $this->m_allno as $value)
{
$url = "<a href=\"index.php?page={$value}\" title=\"第{$value}页\">".$value."</a>";
$url = $value==$this->m_cpage ? "<b>".$value."</b>" : $url;
echo "<li>".$url."</li>\n";
}
echo ("<li><a href=\"index.php?page={$this->m_nextpage}\" title=\"下一页\">></a></li><li><a href=\"index.php?page={$this->m_pcount}\" title=\"最后一页\">>></a></li>");
echo ("</ul>\n");
echo ("</div>\n");
}
}
[ 本帖最后由 zwws 于 2007-3-15 11:04 编辑 ]
作者: zwws 发布时间: 2007-03-15
俺是新人,学习一下:lol
作者: wwwzlmj 发布时间: 2007-04-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28