免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1070 | 回复: 0
打印 上一主题 下一主题

google分页的内核 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-17 13:52 |只看该作者 |倒序浏览
PHP代码:--------------------------------------------------------------------------------
//~~~~~~~~~~使用该类的文件
var $file;
//~~~~~~~~~~页面地址参数
var $para;
//~~~~~~~~~~页面地址
var $address;
//~~~~~~~~~~数据总数
var $total;
var $total_page;
//~~~~~~~~~~每页显示的数量
var $num_per_page=10;
//~~~~~~~~~~~~当前页
var $page_now;
var $offset;
//~~~~~~~~~~~~最末页
var $page_end;
var $offset_end;
//~~~~~~~~~~~~前一页
var $pre_page;
var $offset_pre;
//~~~~~~~~~~~~后一页
var $next_page;
var $offset_next;
        //~~设置各项参数~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        function set_num_per_page($num)
                 {
                 if($num>0)
                        {
                        $this->num_per_page=$num;
                        }
                 }
        function set($file,$total,$offset,$para="")
                 {
                 $this->file=$file;
                 $this->total=$total;
                 $this->para=$para;
                 $this->offset=$offset;
                 $this->page_now=$this->offset/$this->num_per_page+1;
                 $pages=$total/$this->num_per_page;
                 if($pages==0)     {$this->total_page=$pages+1;}
                 else              {$this->total_page=ceil($pages);}
                 $this->page_end=$this->total_page;
                 $this->offset_end=$this->page2offset($this->page_end);
                 if($this->offset1)                {$this->offset_pre  =$this->offset-$this->num_per_page;}     //前一页的offset
                 if($this->offset$this->offset_end){$this->offset_next =$this->offset+$this->num_per_page;}     //前一页的offset
                 if($this->para==""){$this->address=$this->file.'?offset=';}
                 else               {$this->address=$this->file.$this->para.'&offset=';}
                 //echo "0:".ceil(0);
                 //echo " pagenow:".$this->page_now;
                 //echo " pageend:".$this->page_end;
                // echo " offsetend:".$this->offset_end;
                 }
        function page2offset($page_no)
                 {
                 return ($page_no-1)*$this->num_per_page;
                 }
        //~~输出开始~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //页码列表
        function show_page_num_list($num=7,$now_form="",$list_class="")
                 {
                 $output="";
                 $num;                                  //列表元素数
                 $now_form;                             //当前页形式,用{num}做替换,如"{num}"
                 $now_class;                            //当前页样式
                 $list_class;                            //列表样式
                 if($num%2==0){$num++;}
                 $lr_limit=($num-1)/2;
                 $l_page=$this->page_now;
                 $r_page=$this->page_now;
                 $output=str_replace("{num}", $this->page_now, $now_form);
                 for($i=0;$iaddress.$this->page2offset($l_page)."\" class=\"$list_class\">".$l_page." ".$output;
                        }
                 for($i=0;$ipage_end){break;}
                        $r_page++;
                        $output.=" address.$this->page2offset($r_page)."\" class=\"$list_class\">".$r_page." ";
                        }
                 return $output;
                 }
        //上一页
        function show_pre_page($format="上一页",$class="")
                 {
                 $output="";
                 if($this->offset0)
                        {
                        $output="address.$this->offset_pre."\" class=\"$class\">".$format."";
                        }
                 else
                        {
                        $output=$format;
                        }
                 return $output;
                 }
        //下一页
        function show_next_page($format="下一页",$class="")
                 {
                 $output="";
                 if($this->offset$this->offset_end)
                        {
                        $output="address.$this->offset_next."\" class=\"$class\">".$format."";
                        }
                 else
                        {
                        $output=$format;
                        }
                 return $output;
                 }
        //首页
        function show_first_page($format="首页",$class="")
                 {
                 $output="";
                 if($this->offset0)
                        {
                        $output="address."\" class=\"$class\">".$format."";
                        }
                 else
                        {
                        $output=$format;
                        }
                 return $output;
                 }
        //末页
        function show_last_page($format="末页",$class="")
                 {
                 $output="";
                 if($this->offset$this->offset_end)
                        {
                        $output="address.$this->offset_end."\" class=\"$class\">".$format."";
                        }
                 else
                        {
                        $output=$format;
                        }
                 return $output;
                 }
        //跳转菜单
        function show_jump_list($class="")
                 {
                 $output="跳至address."'+this.value\">";
                 for($i=1;$ipage_end;$i++)
                        {
                        $offset=$this->page2offset($i);
                        $output.="offset==$offset?" selected":"";
                        $output.=">第".$i."页";
                        }
                 $output.="";
                 return $output;
                 }
        function show_total_page($format="总页数为({num})页")
                 {
                 return str_replace("{num}", $this->total_page, $format);
                 }
        function show_total($format="共有记录({num})条")
                 {
                 return str_replace("{num}", $this->total, $format);
                 }
        }
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/13004/showart_68516.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP