-
-
- class page {
- //类开始
- /********************************************************
- * $total 记录总数
- * $pagenum 每页显示的条数
- * $url = '' 链接
- * $page->startpage(显示分类统计,字符分类/数字分页,跳转);
- * $page->startpage(true/false, true/false, true/false);
- * site http://bbs.it-home.org
- *********************************************************/
- private $total; //记录总数
- private $pagenum; //每页显示数
- private $page; //当前页数
- private $pages; //总的页数
- private $url; //页面url
- private $aque; //url参数
-
- /* 构造函数 */
- public function page($total, $pagenum, $url='?'){
- $this->total = $total; //总记录数.
- $this->pagenum = $pagenum; //每页显示数.
- $this->url = $this->strsift($url); //判断$url的值是否合法.
- $this->aque = $_get; //页面原来所传递参数.
- $this->page = $this->strsift($_get['page']); //当前页面get(全局变量)方式参数,当前页码.
- $this->page = is_numeric($this->page) ? $this->page : 1; //当前页码不为数字时,则把其设为1.
- $this->pages = ceil($total/$pagenum); //总页数.
- if($this->pagepage = 1; //当页码小于1时,则把其设为1.
- //if($this->page>$this->pages) $this->page = $this->pages; //当页码大于最大页码时,则把其设为最大页码.
- }
- /******************
- * 分页方法
- *******************/
- function startpage($str, $view=true, $jump=true){
- if($view==true) $pagestr .= $this->getcount(); //分页统计信息
- if($str=='str') $pagestr .= $this->getpagestr(); //选择字符分页形式
- else $pagestr .= $this->getpagenum(); //选择数字分页形式
- if($jump==true) $pagestr .= $this->jumpselect(); //跳转
- return $pagestr;
- }
/**********************************************
- * 显示统计信息. 格式:共5条记录 页:2/3
- ***********************************************/
- function GetCount(){
- $CountStr = "共". $this->total ."条记录 页:".$this->page."/".$this->pages." ";
- return $CountStr;
- }
/***********************************************
- * 分页格式形一:第一页 上一页 下一页 末 页
- ************************************************/
- function GetPageStr(){
- $url = $this->url; //获取URL
- //对URL参数进行处理:数组的键是URL变量,数组的值是URL变量的值.
- foreach($this->Aque as $key => $val){
- switch($key){
- case "page":
- $Next = $val + 1;
- $Prev = $val - 1;
- break;
- default:
- $Sque .= "&$key=".$this->StrSift($val);
- }
- }
- if($Next==0) $Next=2;
- //首 页 上一页
- switch($this->page){
- case $this->page
- $pagestr .= "首 页 ";
- $pagestr .= "上一页 ";
- break;
- default:
- $pagestr .= "首 页 ";
- $pagestr .= "上一页 ";
- }
- //下一页 末 页
- switch($this->page){
- case $this->page>=$this->pages:
- $pagestr .= "下一页 ";
- $pagestr .= "末 页 ";
- break;
- default:
- $pagestr .= "下一页 ";
- $pagestr .= "末 页 ";
- }
- //返回分页字符串.
- return $pagestr;
- }
/***********************************************************
- * 分页格式形如:共4307条记录 页:1/72 1 2 3 4 5 6 7 8 9 10
- ************************************************************/
- function GetPageNum(){
- $url = $this->url;
- //对URL参数进行处理:数组的键是URL变量,数组的值是URL变量的值.
- foreach($this->Aque as $key => $val){
- switch($key){
- case $key!="page":
- $Sque .= "&$key=".$this->StrSift($val);
- }
- }
- switch($this->pages){
- //总页数大于12页:
- case $this->pages>12:
- //分页数字前:
- switch($this->page){
- case $this->page>1:
- $pagestr .= " ";
- $pagestr .= " ";
- break;
- default:
- $pagestr .= "
- $pagestr .= "
- }
- //分页数字:1 2 3 4 5 6 当前页码左边6个分页链接,右边6个分页链接.
- for($i=$this->page-6; $ipage+6; $i++){
- if($i>$this->pages) break;
- if($i==$this->page) $pagestr .= $i." ";
- elseif($i>=1) $pagestr .= "$i ";
- }
- //分页数字后: > >>
- switch($this->page){
- case $this->pagepages:
- $pagestr .= ">> ";
- $pagestr .= "> ";
- break;
- default:
- $pagestr .= "> ";
- $pagestr .= ">> ";
- }
- break;
- default:
- //总页数小于12页:
- for($i=1; $ipages; $i++){
- switch($i){
- case $i==$this->page:
- $pagestr .= $i." ";
- break;
- default:
- $pagestr .= "$i ";
- }
- }
- }
- //返回分页字符串.
- return $pagestr;
- }
-
- /************************
- * 定义跳转页. BEGIN
- *************************/
- function JumpSelect(){
- $url = $this->url;
- //对URL参数进行处理:数组的键是URL变量,数组的值是URL变量的值.
- foreach($this->Aque as $key => $val){
- if($key != "page") $Sque .= "&$key=".$this->StrSift($val);
- }
- $SelectStr = "
";
- //返回分页字符串.
- return $SelectStr;
- }
/**********************************
WaStar 网上花店系统
系统特点: 商品多级分类检索、搜索,支持同一商品多重分类,自由设置显示式样 自由设置会员类型,自由设置权限项目,自由分配每种会员类型和每个会员的权限 灵活的商品定价,最多12级价格自由分配给各种会员类型或会员,也可针对单会员单商品特殊定价 强大的会员管理、帐户管理、订单管理功能和一系列帐务查询统计功能 灵活的会员积分系统,自由设置每个积分事件的积分计算方法 灵活的网站内容发布、管理系统,每个栏目可
下载
- * 过滤特殊字符.
- ***********************************/
- private function StrSift($str){
- $str = str_replace(""","",$str);
- $str = str_replace("'","",$str);
- $str = str_replace("[url=file://%22,%22%22,$str/]\","",$str[/url]);
- $str = str_replace("/","",$str);
- $str = str_replace(":","",$str);
- $str = str_replace("?","",$str); //去除会出现"??".
- $str = str_replace(">","",$str);
- $str = str_replace("
- $str = str_replace("%","",$str);
- $str = str_replace("*","",$str);
- $str = str_replace("&","",$str);
- $str = str_replace(".","",$str);
- return $str;
- }
立即学习“PHP免费学习笔记(深入)”;
//类结束
- }
- ?>
-
复制代码
有兴趣的朋友,还可以参考下如下的文章:
一个不错的php分页类的代码
一个实用的php分页类
分页样式表:
-
- /*下拉菜单或文本输入框样式*/
- #JumpSelect{
- background:#159bd0;
- border:1px solid #ffff66;
- color:#ffff66;
- width:37px;
- font-size:11px;
- padding:0 0 0 0;
- margin:0 0 0 0;
- SCROLLBAR-FACE-COLOR: #d0dff7;
- SCROLLBAR-HIGHLIGHT-COLOR: #d0dff7;
- SCROLLBAR-SHADOW-COLOR: #FFFFFF;
- SCROLLBAR-3DLIGHT-COLOR: #FFFFFF;
- SCROLLBAR-ARROW-COLOR: #ffffff;
- SCROLLBAR-TRACK-COLOR: #ffffff;
- SCROLLBAR-DARKSHADOW-COLOR: #d0dff7;
- base-color: #ededed;
- scrollbar-arrow-color: #000;
- scrollbar-highlight-color: #fafafa;
- scrollbar-shadow-color: #fafafa;
- scrollbar-track-color: #ededed;
- scrollbar-face-color: #fafafa;
- scrollbar-darkshadow-color: #ededed;
- scrollbar-3dlight-color: #ededed;
- }
-
复制代码
|