喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

上一主题 下一主题
     
标题: [原创] 我的一个分页类  
 
che361
新手上路
Rank: 1



UID 93702
精华 0
积分 9
帖子 3
金钱 9 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-5-27
状态 离线
我的一个分页类



<?php

                /*
                        翻页类
                */
                class Turnpage extends base_root
                {       
                                        var $db_connect;                     //数据库连接类
                                       
                                        var $CurrentPage;               //当前页
                                        var $PageRecNums = 20;    //每页记录条数
                                        var $PageNums = 0;              //记录总页数
                                       
                                        var $CurrentBigPage;          //当前大页
                                        var $BigPageRecNums = 2; //每大页小页数
                                        var $BigPageNums = 0;     //大页总数
                                       
                                        var $RecNums = 0;              //总记录条数
                                       
                                        var $strSQL;                          //sql语句
                                        var $condition;           //条件
                                        var $strOrderby;
                          /*/ internal use only  
                       
                                        var $db_server = "mysql";
                                        var $db_hostname = "localhost";
                                        var $db_username = "";
                                        var $db_password = "";
                                        var $db_name = "";
                                        var $db_connect = "";
                       
                                       
                                                构造函数
                                                $DB_site  数据库连接类
                                                $sql      sql语句
                                                $orderby  按某数据项排列
                                                $RecsPage 每页显示的记录条数
                                       
                                  function InitDB($server,$host,$username,$pwd,$db)
                                  {
                                                                 
                                                                 $this->db_server = $server;
                                                                 $this->db_hostname = $host;
                                                                 $this->db_username = $username;
                                                                 $this->db_password = $pwd;
                                                                 $this->db_name = $db;
                                                                 $this->db_connect = new DB_Sql_vb;
                                                                 $this->db_connect->connect($this->db_hostname,$this->db_username,$this->db_password,$this->db_name);
                                                                //$this->db_connect->debug=true;
                                                               
                                  }
                                  */
                       
                                        /*
                                                设置函数
                                                $DB_site  数据库连接类
                                                $sql      sql语句
                                                $orderby  按某数据项排列
                                                $RecsPage 每页显示的记录条数
                                        */
                                        function query_exec($sql,$orderby="",$PageRecNums,$BigPageRecNums)
                                        {
                                                               
                                                                $this->strOrderby = $orderby;
                                                                $this->strSQL = $sql;
                                                                $this->PageRecNums = $PageRecNums;
                                                                $this->BigPageRecNums = $BigPageRecNums;
                                                               
                                        }
                                        /*
                                                功  能:返回符记录总条数
                                                参  数:null
                                                返回值:int
                                               
                                                描  述:该函数为外部接口函数用于
                                                                显示记录总数
                                        */
                                        function GetTotalRecords()
                                        {
                                                               
                                                                return $this->RecNums;
                                                               
                                        }
                                       
                                        /*
                                                功  能:返回总页数
                                                参  数:null
                                                返回值:int
                                               
                                                描  述:该函数为外部接口函数用于
                                                                显示总页数
                                        */
                                        function GetTotalPages()
                                        {
                                                               
                                                                return $this->PageNums;
                                                               
                                        }
                                       
                                        /*
                                                功  能:计算记录总条数
                                                参  数:null
                                                返回值:null
                                               
                                                描  述:该函数内部函数不要在外部调用该函数
                                        */
                                        function SetTotalRecords()
                                        {
                                                               
                                                                $this->RecNums = $this->db_connect->num_rows($this->db_connect->query($this->strSQL));
                                                                @mysql_free_result($res);
                                                               
                                        }
                       
                       
                                        /*
                                                功  能:计算总页数
                                                参  数:null
                                                返回值:null
                                               
                                                描  述:该函数是内部函数不要在外部调用
                                        */
                                        function SetTotalPages()
                                        {   
                                                               
                                                                $this->PageNums = Ceil($this->RecNums / $this->PageRecNums);
                                                               
                                        }
                       
                                        /*
                                                功  能:计算大页总页数
                                                参  数:null
                                                返回值:null
                                               
                                                描  述:该函数是内部函数不要在外部调用
                                        */
                                        function SetTotalBigPages()
                                        {
                                                               
                                                                $this->BigPageNums = Ceil(Ceil($this->RecNums / $this->PageRecNums)/$this->BigPageRecNums);
                                                               
                                        }
                                       
                                        //取得每页记录条数
                                        function GetRecsPage()
                                        {
                                                               
                                                                return $this->PageRecNums;
                                                               
                                        }
                       
                                        //有条件查询
                                        function Query($condition)
                                        {
                                                               
                                                                $this->condtion = $condition;
                                                               
                                        }
                       
                                        //功  能:显示分页的页数
                                        //参  数:$pages界面的显示页数
                                        function PageList($param="")
                                        {
                                       
                                                               
                                                                //显示翻页
                                                                if($this->CurrentBigPage >1)  $num .="&nbsp;<a title=\"preview\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage - $this->BigPageRecNums)."$param\" class=\"link1\">首页</a>";
                                                                else  $num .="首页";
                                                                       
                                                                for($i = 1;$i < ($this->BigPageRecNums+1)&& $page < $this->PageNums;$i++)
                                                                {
                                                                                $page = $i + (($this->CurrentBigPage-1)*$this->BigPageRecNums);
                                                                                if($this->CurrentPage == $i)        $num .= "&nbsp;<a href=\"".basename($PHP_SELF)."?page=$page$param\" class=\"link1\"><strong><font color=\"#FF6F6F\">第".$page."页</font></strong></a>";
                                                                                else        $num .= "&nbsp;<a href=\"".basename($PHP_SELF)."?page=$page$param\" class=\"link1\">第".$page."页</a>";
                                                                }
                                                               
                                                                if($this->CurrentBigPage < $this->BigPageNums)        $num .="&nbsp;<a title=\"next\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage + $this->BigPageRecNums)."$param\" class=\"link1\">尾页</a>";
                                                                else        $num .="&nbsp;尾页";
                                                               
                                                                $num .= "&nbsp;&nbsp;&nbsp;合计&nbsp;".$this->RecNums."&nbsp;记录 &nbsp;| 当前在".$this->CurrentPage."/".$this->PageNums."页";
                                                               
                                                                return $num;
                                                               
                                        }
                                       
                                        function & GetRec()
                                        {       
                                                               
                                                                if(!isset($_REQUEST["page"]))        $this->CurrentPage = 1;
                                                                else        $this->CurrentPage = $_REQUEST["page"];
                                                                       
                                                                $this->CurrentBigPage = Ceil($this->CurrentPage / $this->BigPageRecNums);
                                                               
                                                                $this->SetTotalRecords();
                                                                $this->SetTotalPages();
                                                                $this->SetTotalBigPages();
                                                               
                                                                $start = ($this->CurrentPage - 1) * $this->PageRecNums;
                                                                $sql = $this->strSQL." ".$this->$condition." ".$this->strOrderby." limit $start,$this->PageRecNums";
                                                               
                                                                return  $this->db_connect->query($sql);
                                                               
                                        }
                }
?>




中国汽贸网:http://www.che361.com
2007-5-28 08:22 AM#1
查看资料  发短消息  顶部
 
php5
金牌会员
Rank: 6Rank: 6
中级会员


UID 62897
精华 0
积分 1236
帖子 1088
金钱 1236 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2005-1-3
来自 福建
状态 离线
[推荐阅读] 很郁闷。Mysql5的乱码问题
$this->RecNums = $this->db_connect->num_rows($this->db_connect->query($this->strSQL));

这样统计总页数要害死多少人啊
2007-5-30 04:50 PM#2
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 


Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.023976 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP