今天写的分页类......分享
由于是上班时候写的,所以如果全部由部贴出来恐怕对不起公司,所以我把其中的表单跳转删去了。别见怪哦。。。格式写法是比较标准的了
PHP代码:--------------------------------------------------------------------------------
/**********
| +---------------------------------------------------
| CLASS NAME: PageBar
| +---------------------------------------------------
| Author: Arvan [E-mail:Arvan@5n9.com QQ:8817776]
| Create date: 2003-7-17
| Note:
| Do for pagination
| +---------------------------------------------------
| Warning: no...
| +---------------------------------------------------
**********/
class PageBar
{
var $total;
var $onepage;
var $num;
var $pagecount;
var $total_page;
var $offset;
var $linkhead;
function PageBar($total, $onepage, $form_vars=@#@#)
{
$pagecount = $_GET[@#pagecount@#];
$this->total = $total;
$this->onepage = $onepage;
$this->total_page = ceil($total/$onepage);
if (empty($pagecount))
{
$this->pagecount = 1;
$this->offset = 0;
}
else
{
$this->pagecount = $pagecount;
$this->offset = ($pagecount-1)*$onepage;
}
if (!empty($form_vars))
{
$vars = explode("|", $form_vars);
$chk = $vars[0];
$chk_value = $_POST[@#$chk@#];
if (empty($chk_value))
{
$formlink = "";
}
else
{
for ($i=0; $i<sizeof($vars); $i++)
{
$var = $vars[$i];
$value = $_POST[@#$var@#];
$addchar = $vars."=".$value;
$addstr = $addstr.$addchar."&";
}
$formlink = "&".substr($addstr, 0, sizeof($addstr)-1);
}
}
else
{
$formlink = "";
}
$linkarr = explode("pagecount=", $_SERVER[@#QUERY_STRING@#]);
$linkft = $linkarr[0];
if (empty($linkft))
{
$this->linkhead = $_SERVER[@#PHP_SELF@#]."?".$formlink;
}
else
{
$this->linkhead = $_SERVER[@#PHP_SELF@#]."?".$linkft.$formlink;
}
}
#End function PageBar();
function offset()
{
return $this->offset;
}
#End function offset();
function pre_page($char=@#@#)
{
$linkhead = $this->linkhead;
$pagecount = $this->pagecount;
if (empty($char))
{
$char = "[<]";
}
if ($pagecount>1)
{
$pre_page = $pagecount - 1;
return "<a href=\"$linkhead"."pagecount=$pre_page\">$char</a>";
}
else
{
return @# @#;
}
}
#End function pre_page();
function next_page($char=@#@#)
{
$linkhead = $this->linkhead;
$total_page = $this->total_page;
$pagecount = $this->pagecount;
if (empty($char))
{
$char = "[>]";
}
if ($pagecount<$total_page)
{
$next_page = $pagecount + 1;
return "<a href=\"$linkhead"."pagecount=$next_page\">$char</a>";
}
else
{
return @# @#;
}
}
#End function next_page();
function num_bar($num=@#@#, $color=@#@#, $left=@#@#, $right=@#@#)
{
$num = (empty($num))?10:$num;
$this->num = $num;
$mid = floor($num/2);
$last = $num - 1;
$pagecount = $this->pagecount;
$totalpage = $this->total_page;
$linkhead = $this->linkhead;
$left = (empty($left))?"[":$left;
$right = (empty($right))?"]":$right;
$color = (empty($color))?"#ff0000":$color;
$minpage = (($pagecount-$mid)<1)?1<img src="images/smilies/frown.gif" border="0" alt="">$pagecount-$mid);
$maxpage = $minpage + $last;
if ($maxpage>$totalpage)
{
$maxpage = $totalpage;
$minpage = $maxpage - $last;
$minpage = ($minpage<1)?1:$minpage;
}
for ($i=$minpage; $i<=$maxpage; $i++)
{
$char = $left.$i.$right;
if ($i==$pagecount)
{
$char = "<font color=@#$color@#>$char</font>";
}
$linkchar = "<a href=@#$linkhead"."pagecount=$i@#>".$char."</a>";
$linkbar = $linkbar.$linkchar;
}
return $linkbar;
}
#End function num_bar();
function pre_group($char=@#@#)
{
$pagecount = $this->pagecount;
$linkhead = $this->linkhead;
$num = $this->num;
$mid = floor($num/2);
$minpage = (($pagecount-$mid)<1)?1<img src="images/smilies/frown.gif" border="0" alt="">$pagecount-$mid);
$char = (empty($char))?"[<<]":$char;
$pgpagecount = ($minpage>$num)?$minpage-$mid:1;
return "<a href=@#$linkhead"."pagecount=$pgpagecount@#>".$char."</a>";
}
#End function pre_group();
function next_group($char=@#@#)
{
$pagecount = $this->pagecount;
$linkhead = $this->linkhead;
$totalpage = $this->total_page;
$num = $this->num;
$mid = floor($num/2);
$last = $num;
$minpage = (($pagecount-$mid)<1)?1<img src="images/smilies/frown.gif" border="0" alt="">$pagecount-$mid);
$maxpage = $minpage + $last;
if ($maxpage>$totalpage)
{
$maxpage = $totalpage;
$minpage = $maxpage - $last;
$minpage = ($minpage<1)?1:$minpage;
}
$char = (empty($char))?"[>>]":$char;
$ngpagecount = ($totalpage>$maxpage+$last)?$maxpage + $mid:$totalpage;
return "<a href=@#$linkhead"."pagecount=$ngpagecount@#>".$char."</a>";
}
#End function next_group();
function whole_num_bar($num=@#@#, $color=@#@#)
{
$num_bar = $this->num_bar($num, $color);
$pre_group = $this->pre_group();
$pre_page = $this->pre_page();
$next_page = $this->next_page();
$next_group = $this->next_group();
return $pre_group.$pre_page.$num_bar.$next_page.$next_group;
}
#End function whole_bar();
}
#End class PageBar;
/*****
//example
$total = 1000;
$onepage = 20;
$pb = new PageBar($total, $onepage);
$offset = $pb->offset();
$pagebar = $pb->whole_num_bar();
echo $offset."<br>".$pagebar;
return:
0
[<<] [1][2][3][4][5][6][7][8][9][10][>][>>]
*****/
下一篇:给看看这个问题
↓相关文章:
- · 给看看这个问题
- · 版mysql+apache+php in lux安装指南 写的好累得说。。
- · PHP完全手册
- · Web服务器的趋势
- · php在母语方面的支持(转载)
- · 中文注释的php.ini ( darkwings翻译 )
- · PHP3中文文档(续1)
- · PHP3中文文档(续3)
- · PHP3中文文档(续5)
- · php安全之狗尾续貂(转)
- · 如何对PHP程序中的常见漏洞进行攻击(上)
- · MySQL 3.23.40 又发布了
- · PHP 4.06 正式版发布,修正了许多BUG,更加稳定
- · 最近忙于FTP,好站多多!有好多好东东哦!不敢独享!
- · PHP4的核心:Zend (转载自奥索)
- · 三种Web开发主流技术的评价之ASP
- · 三种Web开发主流技术的评价之PHP
- · 在PHP中使用灵巧的体系结构(摘)
- · 聊天室技术 - 密谈的实现
- · 规范1
- · phpMyAdmin又出了新版本phpMyAdmin-2.2.3-rc1
- · PHP 4.1.0 出版公告(中英对照版)补 1
- · PHP的面向对象编程
- · php重大发现!:)
- · PHP函数索引(4)
- · php函数索引(1)
- · 是你期待的吗? 从Zend Engine 2.0的设计蓝图(草稿)看PHP的将来
- · Mysql权限系统工作原理
- · 加固PHP环境(转)
- · 先做点好事,转点东东来,用PHP和MySQL构建一个数据库驱动的网站(-)
- · 用PHP和MySQL构建一个数据库驱动的网站(三)
- · 用PHP和MySQL构建一个数据库驱动的网站(四)
- · 用PHP和MySQL构建一个数据库驱动的网站(7)
- · 用PHP和MySQL构建一个数据库驱动的网站(十)
- · php中echo <<< 的应用
- · 正则表达式语法(转)
- · PHP的面向对象编程:开发大型PHP项目的方法(三)(转载)
- · PHP的面向对象编程:开发大型PHP项目的方法(五)(转载)
- · 规范3
- · 认知Web服务器
- · PHP脚本数据库功能详解(1)
- · PHP脚本数据库功能详解(3)
- · 第1次亲密接触PHP5(2)
- · 第1次亲密接触PHP5(1)
- · Oracle 常见问题解答

