查看: 5475|回复: 3
打印 上一主题 下一主题

PHP多功能分页类

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-5 11:28:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
  1. <?php
  2. /**
  3. * @descrition
  4. * 此类为PHP+MYSQL的分页显示类,此类是通过自己先前写的分页函数修改而来,本类继承了当前
  5. * 分页显示的绝大部分功能,并且对这么功能可以筛选,选择自己所需的功能,本类提供的功能有:
  6. * 基本翻页按扭(可对按扭自行设计)、分页统计功能(对当前页的数据进行统计,使用户更加一目
  7. * 了然)、跳转功能(这里我们提供了两种跳转方式,可以通过设置相关参数进而来选择自己所需要
  8. * 的跳转方式,这两种跳转方式为:下拉式菜单跳转文本输入框跳转,可以通过设置id为JumpSele
  9. * ct的元素的样式来改变跳转框的界面)、对跳转的页号,提供了加密功能,这也是可以根据相关的
  10. * 参数设置来定制的.
  11. * @Author:            hqlong
  12. * @CreatTime:        2006-04-06
  13. * @UpdateTime-1:    2006-07-26
  14. * @UpdateTime-1:    2006-11-07
  15. * @LastUpdateTime:    2007-1-21
  16. * @CopyRight: hqlong
  17. * @Introduce:     
  18. * 1. 首先实例化这个类($sql:sql查询语句,如果规定了limit,则每页显示数以limit后的数目
  19. *      为准,如果末给定,刚采用默认显示条数,$CycNum:循环显示的页号数,缺省显示$CycNum*2
  20. *    条,此参数可以缺少,该参数的所有功能得要在$IsDisNum设为true时才有效。
  21. *    $page = new ($sql,$CycNum);
  22. * 2. 调用分页函数,并返回经格式化后的sql语句,$Sortid:排序ID,整个显示都是依$Sortid来
  23. *      进行排序的,$IsEncode:是否对页号加密,该参数可以省略,缺省时不加密该,该参数值为
  24. *    bool型,取值范围true,false。$IsNeedStat:是否显示统状况,可省略,缺省时不显示,
  25. *    取值范围true、false,$SortMethod为排序方式,取值范围up or down,up为升序, down
  26. *    为降序,如果不提供,只默认为down
  27. *    $sql = $page->StartPage($Sortid,$IsEncode = false,$IsNeedStat = false,
  28. *      $SortMethod = "down");
  29. * 3. 接下来就是执行$sql,和平时查询数据的操作一样
  30. *    $result = mysql_query($sql)
  31. *    while($arr = mysql_fetch_array($result)){
  32. *            echo $arr[0];//这里打印输入
  33. ×  }
  34. * 4. 显示翻页按扭,和自己定制的一种功能 $ButtomArray:翻页按扭定置数组,定置普通按扭的
  35. *    形式如 $ButtomArray = array("首页","上页","下页","末页"),这里是一个数组,而且
  36. *    数组元素个素为四,如果不按此规定设置,一切设置将视为无效,显示将按程序默认方式显示
  37. *    $JumpType:定制跳转框,取值范围为select、text、none,其中select为下拉菜单显示框
  38. *    ,text文本输入框,none不定制任何跳转框,此处注意,当设置成text时,不能对页号进行加
  39. *    密,此参数可省略,缺省状况下不显示任何跳转框,$IsDisNum:是否显示循环页号数,取值范
  40. *    围为true,false,此参数可以省略,缺省状况下为false,即,不显示循环页号.
  41. *    $page->EndPage($ButtonArray,$JumpType = "none",$IsDisNum = false)
  42. * 5. 如果对程序提供的统计显示位置感到不满意,可以通过调用$page->PageStat()来得到统计
  43. *    状态,此返值字符串,即可以把这些统计文字放在你想放的任何地方
  44. * @Example:
  45. *     $sql = "select iBookId,vBookName from xx_book limit 0,10";
  46. *    $page =  new Page($sql);
  47. * //StartPage($Sortid,$IsEncode = false,$IsNeedStat = false,$SortMethod = "down")
  48. *    $sql =  $page->StartPage("iBookId",false,true,"down");
  49. *    $result = mysql_query($sql);
  50. *    while($arr = mysql_fetch_array($result)){
  51. *        echo $arr[1]."
  52. ";
  53. *    }
  54. *    $ButtonArray = array("首页","上页","下页","末页");
  55. *     //可单独显示
  56. *    //echo "
  57. ".$page->PageStat()."";
  58. *    echo $page->EndPage($ButtonArray,'text',true);
  59. *
  60. */
  61. class Page{
  62.     /**
  63.      * @description
  64.      * 每页记录数,如果未给定,则默认显示数为 10 条
  65.      * @var int
  66.     */
  67.     private $PageSize = 10;
  68.     /**
  69.      *
  70.      * @description
  71.      * 总页数
  72.      * @var int
  73.     */
  74.     private $TotalPage;
  75.     /**
  76.      * @description
  77.      * 总记录数
  78.      * @var int
  79.     */
  80.     private $RecordNum;
  81.     /**
  82.      * @description
  83.      * 记录总数
  84.      * @var int
  85.     */
  86.     private $NowPage;
  87.     /**
  88.      * @description
  89.      * 执行的sql语句
  90.      * @var int
  91.     */
  92.     private $QueryString;
  93.     /**
  94.      * @description
  95.      * 地址栏中的页数是否加密
  96.      * 默认不加密
  97.      * @var string
  98.     */
  99.     private $IsEncode = false;
  100.     /**
  101.      *
  102.      * @description 是否需要显示当前显示状态
  103.      * @var unknown_type
  104.     */
  105.     private $IsNeedStat;
  106.     /**
  107.      * ******************************************************
  108.      * @description 循环显示页号数
  109.      * 默认显示数 10 条
  110.      * @var int
  111.      */
  112.     private $CycNum = 5;     
  113.     /**
  114.      *
  115.      * @description 析构函数,该分页类创建对象时,自动调用
  116.      * 对sql语句进行判断,获取文章每页显示数
  117.      * @param string $sql
  118.     */
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
2#
 楼主| 发表于 2007-10-5 11:28:17 | 只看该作者
台州网址导航
  1. public function __construct($sql,$CycNum = 5){
  2.         if(!@mysql_ping()){
  3.             echo "Please check your database link";
  4.             exit;            
  5.         }
  6.         if(is_numeric($CycNum)){
  7.             $this->CycNum = $CycNum;
  8.         }else{
  9.             $this->CycNum = $this->CycNum;
  10.         }
  11.         if(trim($sql) != ""){
  12.             /*if(preg_match("/limit/",$sql)){
  13.                 list($sql,$limit)    =    explode("limit",$sql);
  14.             }else{
  15.                 list($sql,$limit)    =    explode("LIMIT",$sql);
  16.             }
  17.             $this->QueryString = $sql;
  18.             list($cnt1,$cnt2)    =    explode(",",$limit);
  19.             if(!empty($cnt2)){
  20.                 $this->PageSize = $cnt2;
  21.             }elseif(!empty($cnt1)){
  22.                 $this->PageSize = $cnt1;
  23.             }else{
  24.                 $this->PageSize = $this->PageSize;
  25.             }*/
  26.             /**修改于2006年11月23日,解决出现Notice: Undefined offset: 2***/
  27.             if(preg_match("/limit/",$sql)){
  28.                 list($sql,$limit)    =    explode("limit",$sql);
  29.             }else if(preg_match("/LIMIT/",$sql)){
  30.                 list($sql,$limit)    =    explode("LIMIT",$sql);
  31.             }
  32.             //$this->QueryString = $sql;
  33.             if(isset($limit)){
  34.                 list($cnt1,$cnt2)    =    explode(",",$limit);
  35.                 if(!empty($cnt2)){
  36.                     $this->PageSize = $cnt2;
  37.                 }elseif(!empty($cnt1)){
  38.                     $this->PageSize = $cnt1;
  39.                 }else{
  40.                     $this->PageSize = $this->PageSize;
  41.                 }
  42.             }
  43.             $this->QueryString = $sql;
  44.             unset($cnt1);
  45.             unset($cnt2);
  46.         }
  47.     }
  48.     /**
  49.      *
  50.      * @description 获取相应规定数目的记录
  51.      * 并计算出总记录数,总页数等比较重要的参数
  52.      * @param int $Sortid
  53.      * 排序ID
  54.      * @param bool $IsEncode
  55.      * 页号是否加密,true为加密,false为不加密
  56.      * @return string
  57.      */
  58.     public function StartPage($Sortid,$IsEncode = false,$IsNeedStat = false,$SortMethod = "down"){
  59.         $Result = mysql_query($this->QueryString);
  60.         $this->RecordNum = @mysql_num_rows($Result);
  61.         $this->TotalPage = ceil($this->RecordNum/$this->PageSize);
  62.         /*******************************************************
  63.          * 初始化类属性IsNeedStat
  64.          *******************************************************/
  65.         if($IsNeedStat === true or $IsNeedStat === false){
  66.             $this->IsNeedStat = $IsNeedStat;
  67.         }else{
  68.             echo "Warning:方法StartPage中的参数IsNeedStat只能是bool";
  69.         }
  70.         /*******************************************************
  71.          * 初始化类属性IsEncode
  72.          *******************************************************/
  73.         if($IsEncode === true or $IsEncode === false){
  74.             $this->IsEncode = $IsEncode;
  75.         }else{
  76.             echo "Warning:方法StartPage中的参数IsEncode只能是bool";
  77.         }
  78.          
  79.         /*******************************************************
  80.          *接收从url中传过来的当前页数,如果非数字,刚获取其整数值
  81.          *******************************************************/
  82.         if(isset($_REQUEST['NowPage'])){
  83.             $this->NowPage = intval($_REQUEST['NowPage']);
  84.         }
  85.          
  86.         /*******************************************************
  87.          *根据$IsEncode的值来判断页号是否解密,如果$IsEncode的值非bool,
  88.          *则给出警告信息,但并不影响程序执行,且默认不加密.
  89.          *******************************************************/
  90.         if($this->IsEncode === true){
  91.           $this->NowPage = intval($this->StrDecode($_REQUEST['NowPage']));
  92.         }
  93.         //排列顺序 up 升序 down 降序
  94.         if(isset($SortMethod) && $SortMethod == "up"){
  95.             $SortMethod = "ASC";
  96.         }elseif(isset($SortMethod) && $SortMethod == "down"){
  97.             $SortMethod = "DESC";
  98.         }else{
  99.             echo "Warning:方法StartPage中的参数SortMethod只能是down或者up";
  100.         }
  101.         if(!isset($this->NowPage)){
  102.             $this->NowPage = 1;
  103.         }elseif($this->NowPage <= 0){
  104.             $this->NowPage = 1;
  105.         }elseif($this->NowPage > $this->TotalPage){
  106.             $this->NowPage = $this->TotalPage;
  107.         }else{
  108.             $this->NowPage = $this->NowPage;
  109.         }
  110.         $OffSet = $this->PageSize * ($this->NowPage -1);
  111.         $sql = $this->QueryString." ORDER BY ".$Sortid." ".$SortMethod." LIMIT ".$OffSet.",".$this->PageSize;
  112.         return $sql;
  113.     }
  114.     /**
  115.      *
  116.      * @description
  117.      * 翻页按扭的显示,如:首页 上页 下页 末页,可以定制自定义翻页按扭样式
  118.      * 此函数也是 外面调用此类的入口.将返回经处理后的sql语
  119.      * @param array $ButtonArray
  120.      * 翻页按扭形式,用户可随意定制:如:
  121.      * $ButtonArray = array("首页","上页","下页","末页");
  122.      * @param string $JumpType
  123.      * 附加选项,通过能参数,可定制跳转框,select 下拉跳转框,text 文
  124.      * 本输入跳转框,none 不定制任何跳转框
  125.      * @param bool $IsDisNum
  126.      * 是否显示循环分页,true 显示 false 不显示;如:
  127.      * 1 2 3 4 5 6 7 8 9 10
  128.      * @return string
  129.      */
  130.     public function EndPage($ButtonArray,$JumpType = "none",$IsDisNum = false){
  131.         $FirstPage = 1;
  132.         $PrePage       = $this->NowPage - 1;
  133.         $NextPage       = $this->NowPage + 1;
  134.         $LastPage       = $this->TotalPage;
  135.         /**
  136.          * 根据参数$ButtomArray来得到用户定制的按扭,如果参数给出类型
  137.          * 不正确,则采用系统默认按扭
  138.          */
  139.         if(!is_array($ButtonArray) or count($ButtonArray) != 4){
  140.             $ButtonArray = array("First","Precede","Next","Last");
  141.         }
  142.         if($this->IsNeedStat === true){
  143.             $ReturnStr   = "".$this->PageStat()."";
  144.         }else{
  145.             $ReturnStr   = "";     
  146.         }         
  147.         $ReturnStr  .= $this->ToPage($FirstPage,$ButtonArray[0],"First");
  148.         $ReturnStr  .= " ";
  149.         $ReturnStr  .= $this->ToPage($PrePage,$ButtonArray[1],"Pre");
  150.         if($IsDisNum === true){
  151.             $ReturnStr  .= " ".$this->DisPageNum()." ";
  152.         }elseif($IsDisNum === false){
  153.             $ReturnStr .= " ";
  154.         }else{
  155.             /**
  156.              * 对参数的合法性,进行审核
  157.              */
  158.             echo ('Warning:方法EndPage()中参数$IsDisNum的类型是bool,只能是 true或者false
  159. ');
  160.             $ReturnStr .= " ";
  161.         }
  162.         $ReturnStr  .= $this->ToPage($NextPage,$ButtonArray[2],"Next");
  163.         $ReturnStr  .= " ";
  164.         $ReturnStr  .= $this->ToPage($LastPage,$ButtonArray[3],"Last");
  165.         $ReturnStr  .= " ";
  166.         if($JumpType === 'select'){
  167.             $ReturnStr .= $this->JumpSelect('select');
  168.         }elseif($JumpType === 'text'){
  169.             $ReturnStr .= $this->JumpSelect('text');
  170.         }elseif($JumpType === 'none'){
  171.             //待写入
  172.         }else{
  173.             echo ('Warning:方法EndPage()中参数$JumpType 的值只能是 select text none
  174. ');
  175.         }
  176.         return $ReturnStr;
  177.     }
  178.     /**
  179.      *
  180.      * @description
  181.      * 创建翻页按扭,并根据$Flag 的值来设置按扭是否可用,即:按
  182.      * 扭是否带有链接,此此函数外界不可访问,属于该类私有方法
  183.      * @param int $Page 将要跳转的页数
  184.      * @param string $Msg 跳转按扭名称
  185.      * @param string $Flag 按扭显示类型的判断
  186.      * @return string
  187.      */
复制代码
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
3#
 楼主| 发表于 2007-10-5 11:28:35 | 只看该作者
台州网址导航
  1. private function ToPage($Page,$Msg,$Flag = ''){
  2.         /*
  3.          * 对$this->IsEncode为真,则对页数进行解密
  4.          */
  5.         if($this->IsEncode === true){
  6.             $Page = $this->StrEncode($Page);
  7.         }         
  8.         $Url = $this->GetUrl($Page);
  9.         $UrlStr = "".$Msg."";
  10.         /*
  11.          *如果当前页是小于或者等于第1页,那么首页和上页不显示链接
  12.          * 如果当前页大于或者等于最后一页,那么末页和下页不显示链接
  13.          * 对于其它情况,四个跳转按扭都显示*******
  14.          */
  15.         if(($this->NowPage <= 1 and ($Flag == "First" or $Flag == "Pre"))
  16.         or ($this->NowPage >= $this->TotalPage and($Flag == "Next" or $Flag == "Last"))){
  17.             $UrlStr = $Msg;
  18.         }else{
  19.             //待写入
  20.         }
  21.         return $UrlStr;
  22.     }
  23.     /**
  24.      *
  25.      * @description
  26.      * 获取当前的URL地址,并对将要跳转的地址做出修改,此方法也属于私有
  27.      * 方法,外界不可访问,只能被类内部调用
  28.      * @param int  $Page 将要跳转的页数
  29.      * @return string
  30.      */
  31.     private function GetUrl($Page){
  32.     /*下面代码于2006年12月1日进行了修改,其中$_SERVER['REMOTE_ADDR']被修改成下面的
  33.      *$_SERVER['SERVER_ADDR'];$_SERVER['REMOTE_ADDR']为远程客户端地址,而$_SERVE
  34.      *R['SERVER_ADDR']为服务器端地址SERVER_ADDR*/
  35.         if($_SERVER['SERVER_PORT'] == 80){
  36.             $Url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  37.         }else{
  38.             $Url = "http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
  39.         }
  40.     //    $Url = preg_replace("/\?NowPage=[0-9]*&?/i","",$Url);
  41.     //    $Url = preg_replace("/&NowPage = [0-9]*&?/i","",$Url);
  42.         /*** *********************************************
  43.          * 对url做出修改,将url中的?NowPage = "任何字符" 或者
  44.          * $NowPage = "任何字符" 替换成 空,供下面对url的增加
  45.          *************************************************/
  46.         $Url = preg_replace("/\?NowPage=.*&?/i","",$Url);
  47.         $Url = preg_replace("/&NowPage=.*&?/i","",$Url);
  48.         /***************************************************
  49.          *如果$Page = 0,则只取得当前URL,不再加向url全传值
  50.          ***************************************************/
  51.         if($Page === 0){
  52.             return $Url;
  53.         }
  54.         /*判断先前是否已存在url传值,如果存在,
  55.          *则加&NowPage=,否则加?/NowPage =
  56.          */
  57.         if(preg_match("/\?/",$Url)){
  58.             $Url = $Url."&NowPage=".$Page;
  59.         }else{
  60.             $Url = $Url."?NowPage=".$Page;
  61.         }
  62.          
  63.         return $Url;
  64.     }
  65.     /**
  66.      *
  67.      * @description
  68.      * 对分页状况的一个统计,此方法可以定制,
  69.      * 即:可要,也可不要,如需要显示当前状况
  70.      * 在外部需显示的地方调用此方法即可.
  71.      * @return string
  72.      */
  73.     public function PageStat(){
  74.         $StatString  = "共有 ".$this->RecordNum." 条记录  ";
  75.         $StatString .= "当前第 ".$this->NowPage." 页/共有 ".$this->TotalPage." 页 ";
  76.         $StatString .= "每页显示 ".$this->PageSize." 条";
  77.         return $StatString;
  78.     }
  79.     /**
  80.      *
  81.      * @description
  82.      * 创建两种跳转框,一种下拉跳转菜单,一种文本输入菜单
  83.      * 下拉菜单跳转框,当鼠标选中需跳转的页后,程序自动
  84.      * 进行跳转到所指定的页数,文本输入菜单则是用户在文本
  85.      * 框内输入要跳转的页数,鼠标外部单击,刚自己跳转
  86.      * @param string $JumpType
  87.      * 跳转菜单类型 select 下拉跳转框 text 文章输入跳转框,
  88.      * none 不定制任何跳转框
  89.      */
  90.     private function JumpSelect($JumpType){
  91.         $Url = $this->GetUrl(0);//获取当前url
  92.         /**
  93.          *判断先前是否被已经URL传值******
  94.          */
  95.         if(preg_match("/\?/",$Url)){
  96.             $Url = $Url."&NowPage";
  97.         }else{
  98.             $Url = $Url."?NowPage";
  99.         }
  100.         $JumpString  = "转到";
  101.         if($JumpType === 'select'){
  102.             $JumpString .= "<select id='JumpSelect' name='NowPage' size='1'";
  103.             $JumpString .= "onChange=\"window.location = '".$Url."='+this.value\">";
  104.             for($i = 1; $i <= $this->TotalPage;$i++){
  105.                 /**选中当前页*/
  106.                 if($this->NowPage == $i){
  107.                     $Extra = "selected";
  108.                 }else{
  109.                 $Extra = "";
  110.                 }
  111.                 if($this->IsEncode === true){
  112.                     $JumpString .= "StrEncode($i)."' ".$Extra.">".$i."";
  113.                 }else{
  114.                     $JumpString .= "".$i."";
  115.                 }
  116.             }
  117.             $JumpString .= " 页";
  118.         }elseif($JumpType === 'text'){
  119.             $Title = "鼠标外部单击,文章转向";
  120.             $JumpString .= "NowPage."'onBlur=\"";
  121.             $JumpString .= "javascript:if(isNaN(parseInt(this.value)) || parseInt(this.value)";
  122.             $JumpString .= " > ".$this->TotalPage."){alert('您输入的数字只能在 1 ~ ".$this->TotalPage;
  123.             $JumpString .= "之间,请重新输入'); return false;}location.href='".$Url."='+parseInt(this.value)\" title='".$Title."'>";
  124.             $JumpString .= " 页";
  125.         }else{
  126.             
  127.         }
  128.         return $JumpString;
  129.     }
  130.     /**
  131.      *
  132.      * @description 对页数进行循环显示,如 1 2 3 4 5
  133.      * @return unknown
  134.      */
  135.     private function DisPageNum(){
  136.         //循环显示规定数目的页号
  137.         if(!isset($PageNumString)){
  138.             $PageNumString = "";
  139.         }
  140.         for($i = $this->NowPage - $this->CycNum;$i < $this->NowPage + $this->CycNum;$i++){
  141.             if($i <= 0){
  142.                 $i = 0;
  143.                 continue;
  144.             }elseif($i > $this->TotalPage){
  145.                 break;
  146.             }elseif($i == $this->NowPage){
  147.                 $PageNum = "[".$i."]";
  148.                 $PageNumString .= $this->ToPage($i,$PageNum)." ";
  149.             }else{
  150.                 $PageNumString .= $this->ToPage($i,$i)." ";
  151.             }
  152.         }
  153.         return $PageNumString;
  154.     }
  155.     /**
  156.      *
  157.      * 对字符串进行加密
  158.      * @param string $str
  159.      * @return string
  160.      */
  161.     private function StrEncode($str){
  162.         $encodeArr = str_split($str);
  163.         $encode = '';
  164.         for($i = 0; $i < count($encodeArr); $i++){
  165.             $encodeStr = ord($encodeArr[$i]) + $i;
  166.             $encode .= ($encodeStr)."|<<&>>|";
  167.         }
  168.         return urlencode(base64_encode(($encode)));
  169.     }
  170.     /**
  171.      *
  172.      * @description 对字符加密的字符串进行解密
  173.      * @param string $str
  174.      * @return string
  175.      */
  176.     private    function StrDecode($str){
  177.         $decode = base64_decode(urldecode($str));
  178.         $decodeArr = explode("|<<&>>|",$decode);
  179.         $decodeStr = '';
  180.          for($i = 0;$i < count($decodeArr);$i++){
  181.              $decode = $decodeArr[$i];
  182.              $decode = $decode;
  183.              $decodeStr .= chr($decode - $i);
  184.          }
  185.          return $decodeStr;
  186.     }
  187.     /**
  188.      *
  189.      * @description
  190.      * 本分页类的析构函数
  191.      */
  192.     public function __destruct(){
  193.         //echo "destruct";
  194.     }
  195. }
  196. ?>
复制代码
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
4#
 楼主| 发表于 2007-10-5 11:30:00 | 只看该作者
台州网址导航

  1. /*链接面号的样式*/
  2. .pagelink {
  3. margin:0px 0px 0px 0px;
  4. padding:0px 3px 0px 3px;
  5. border:1px solid #159BD0;
  6. }
  7. /*下拉菜单或文本输入框样式*/
  8. #JumpSelect{
  9.   background:#159bd0;
  10.   border:1px solid #ffff66;
  11.   color:#ffff66;
  12. }

  13. <?php
  14. /**
  15.   * @Author:   hqlong
  16.   * @CreatTime:  2006-04-06
  17.    * @UpdateTime-1: 2006-07-26
  18.      * @UpdateTime-2: 2006-11-07
  19.   * @UpdateTime-2: 2006-1-21
  20.   * @LastUpdateTime: 2007-3-
  21. 16
  22.   */
  23.   require_once("page.class.php");
  24. $conn = mysql_connect("localhost","root","qinglong");
  25. mysql_select_db("xx_libb");
  26. $sql = "select iBookId,vBookName from xx_book limit 0,10";
  27. /**
  28.   *  首先实例化这个类($sql:sql查询语句,如果规定了limit,则每页显示数以limit后的数目
  29.   *  为准,如果末给定,刚采用默认显示条数,$CycNum:循环显示的页号数,缺省显示$CycNum*2
  30.   *  条,此参数可以缺少,该参数的所有功能得要在$IsDisNum设为true时才有效。
  31.   * 原型$page = new ($sql,$CycNum);
  32.   */
  33. $page =  new Page($sql,5);
  34. /*********
  35.   * 方法原型
  36.   *调用分页函数,并返回经格式化后的sql语句,$Sortid:排序ID,整个显示都是依$Sortid来
  37.   *进行排序的,$IsEncode:是否对页号加密,该参数可以省略,缺省时不加密该,该参数值为
  38.   *bool型,取值范围true,false。$IsNeedStat:是否显示统状况,可省略,缺省时不显示,
  39.   *取值范围true、false,$SortMethod为排序方式,取值范围up or down,up为升序, down
  40.   *为降序,如果不提供,只默认为down
  41.   $sql = $page->StartPage($Sortid,$IsEncode = false,$IsNeedStat = false,$SortMethod = "down");
  42. ****************/
  43. $sql =  $page->StartPage("iBookId",false,false,'down');
  44. $result = mysql_query($sql);
  45. while($arr = mysql_fetch_array($result)){
  46.   echo $arr[1]."
  47. ";
  48. }
  49. //按扭名称
  50. //$ButtonArray = array("","<<",">>","");
  51. $ButtonArray = array("<","<<",">>",">");
  52. /*显示分页状况,此功能和IsNeedStat设置为ture里的功能一样,如果对系统系统统计状态的位置不
  53. * 能满足你的要求,那么我们就可能直接调用系统内部状态统计函数*/
  54.   //echo "
  55. ".$page->PageStat()."";
  56. /*原型$page->EndPage($ButtonArray,$JumpType = "none",$IsDisNum = false)
  57.  $JumpType可选参数 select,text,none.IsDisNum是否显示$CycNum*2条页数
  58. */
  59. echo $page->EndPage($ButtonArray,"select",true);
  60. //echo $page->DisPageNum();

  61. ?>
复制代码
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表