BluePage通用分頁類助開發者提高開發效率(2)_PHP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:解決setcookie語句問題的方法
      解決辦法: 打開php_ini,搜索output_bufferfing,把前面的分號去掉,把off修改為on,或者設置一個數值。就可以了。 這類語句,造成這個原因是因為setcookie語句的問題。 cookie本

      以下為引用的內容:
      <?php
      include ( "lib/BluePage.class.php" ) ;
      $pBP = new BluePage ;
      $intCount = 1000 ; // 假設記錄總數為1000
      $intShowNum = 10 ; // 每頁顯示10
      $pBP->_getlink = false ; // 取消取得鏈接
      $pBP->_getqs = false ; // 取消取得Query String
      //返回分頁數字(省資源)
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      //print_r($aPDatas); //打印出來看看

       

      //只要最大頁,上一頁,與下一頁和當前頁以及offset返回(最省資源)
      $aPDatas = $pBP->get( $intCount, $intShowNum , 0 );
      //print_r($aPDatas); //打印出來看看
      ?>


      取得offset

      以下為引用的內容:

      <?php
      include ( "lib/BluePage.class.php" ) ;
      $pBP = new BluePage ;
      $intCount = 1000 ; // 假設記錄總數為1000
      $intShowNum = 10 ; // 每頁顯示10
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      $offset = $aPDatas['offset'] ;
      ?>


      非數據庫分頁:

      比如有一篇文章長度是10000字節,要想每2000字節分為一頁,那怎么辦呢?

      以下為引用的內容:

      <?php
      include ( "lib/BluePage.class.php" ) ;
      $pBP = new BluePage ;
      $strLen = strlen($strSubContent); //假設內容總長度,這個自己計算取得
      $strSubLen = 2000 ; // 每頁數據長度
      $aPDatas = $pBP->get( $strLen, $strSubLen );
      $offset = $aPDatas["offset"] ;
      //取得當前頁的內容
      $strSubContent = fn_substr( $strSubContent, $offset , $strSubLen ) ; //截取函數自己寫
      ?>

      一些屬性:

      8.1 你使用的變量不是page,而是其他,比如是 pn :

      以下為引用的內容:

      <?php
      $pBP->_var = 'pn' ;
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>

      8.2 $this->_prefix有什么作用?

      當你的分頁是類似于page=pp123這樣的數字前面有字符的時候,$this->_prefix就有用了

      以下為引用的內容:
      <?php
      $pBP->_prefix = 'pp' ; // 如page=pp123的 pp
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>

      8.3 $this->_postfix有什么作用? :

      當你的分頁是類似于page=123p這樣的數字后面有字符的時候,$this->_postfix就有用了

      以下為引用的內容:

      <?php
      $pBP->_postfix = 'p' ; // 如page=123p的 p
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>


      8.4 $this->_prefix和$this->_postfix能否同時使用? :

      當然可以。當你的分頁是類似于page=pn123ccc 這樣的數字后面有字符的時候,就兩個一起用

      以下為引用的內容:

      <?php
      $pBP->_prefix = 'pn' ;
      $pBP->_postfix = 'ccc' ;
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>

      8.5 $this->_pos有什么用? :

      它的作用是 當前頁在分頁條中的位置設定,比如設為3,當前頁是8,那么數字8就分處在分頁條的第三位即: 6 7 8 9 10 11 12 13 14 15

      以下為引用的內容:

      <?php
      $pBP->_pos = 5 ; //把當前頁放到第五位
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>


      8.6 $this->_symbol有什么用? :

      連接符

      以下為引用的內容:

      <?php
      $pBP->_symbol= '&' ; //使用&為鏈接符
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>

      8.7 $this->_getqs有什么用? :

      是否取得Query String。默認取得,為false則不取得?晒澥≠Y源,但如果要取得鏈接與html的時候,它會為true

      以下為引用的內容:

      <?php
      $pBP->_getqs = false ;
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>


      8.8 $this->_getlink有什么作用? :

      this->_getlink默認為true,即表示取得分頁的鏈接,為false時,有關*ln鍵名的變量,都不會有值它的作用在于,1 適用于手工設置鏈接的人 2 節省資源

      以下為引用的內容:

      <?php
      $pBP->_getlink = false ;
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>


      8.9 $this->_encode有什么作用? :

      $this->_encode默認為true,即表示使用htmlspecialchars對Query String過濾

      以下為引用的內容:

      <?php
      $pBP->_encode= false ;//不過濾query string
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      ?>


      最后:

      關于BluePage.default.inc.php配置文件

      這個是默認的配置文件。你可以將面的內容拷貝一份,保存為另一個配置。比如命名為page.abc.inc.php 假設當前訪問的是list.php文件,在list.php同級目錄下有一目錄保存config,如./config目錄,而你將page.abc.inc.php保存在./config目錄了。

      以下為引用的內容:

      <?php
      $pBP->_encode= false ;//不過濾query string
      $aPDatas = $pBP->get( $intCount, $intShowNum );
      $strHtml = $pBP->getHTML( $aPDatas, './config/page.abc.inc.php' ); //路徑要正確
      ?>
       



      請根據你的頁面輸出編碼,保存相應編碼格式。就像你做模板一樣。

      如果你的頁面是utf-8格式的,請保存配置文件為utf-8格式。注意,只是改page.abc.inc.php編碼,類文件的編碼請不要改動。

      補充一點:

      如果覺得沒有取記錄總數的函數不方便,你可以自已在類里面加上取總數的函數,或者使用外部函數

      我們在實際應用中,取記錄數的方法是跟隨項目對象的,所以一般不加在分頁類里面.

      如果你沒有自己取記錄數的方法,你可以在分頁類中加上,或者加到外部

      [php]

       

      程序示例:

      以下為引用的內容:

      <?php
      //這是mysql的函數,你可以加一個名為msGetCount的函數支持mssql
      //加到類里面,或作為外部函數
      function myGetCount( $strQuery , $pDBC )
      {
      $resResult = @mysql_query ( $strQuery , $pDBC ) ;
      while ( $arrRow = @mysql_fetch_row ( $resResult ) )
      {
      $intCount = intval($arrRow[0]);
      }
      @mysql_free_result( $resResult ) ;
      return $intCount ;
      }

      //這是SQLserver的函數
      //加到類里面,或作為外部函數
      function msGetCount( $strQuery , $pDBC )
      {
      $resResult = @mssql_query ( $strQuery , $pDBC ) ;
      while ( $arrRow = @mssql_fetch_row ( $resResult ) )
      {
      $intCount = $arrRow[0];
      }
      @mssql_free_result( $resResult ) ;
      return intval( $intCount ) ;
      }

      //使用例子
      $dbconn = mysql_connect ( 'localhost' , 'dbname' , 'password' ) ;
      mysql_select_db( 'yourdb' , $dbconn ) ;
      $strQuery = 'SELECT COUNT(`id`) FROM TABLE WHERE 1' ;

      include ( "lib/BluePage.class.php" ) ;
      $pBP = new BluePage ;

      //作為外部函數時
      $intCount = myGetCount( $strQuery , $dbconn ) ; //取得了記錄數
      //如果是SQLserver
      $intCount = msGetCount( $strQuery , $dbconn ) ; //取得了記錄數

      //作為類的方法時
      $intCount = $pBP->myGetCount( $strQuery , $dbconn ) ;//取得了記錄數
      //如果是SQLserver
      $intCount = $pBP->msGetCount( $strQuery , $dbconn ) ;//取得了記錄數

      $pBP->get( $intCount, 10 ); //取得分頁數據
      ?>

      當然,我們并不鼓勵將數據庫操作放入分頁類中 。

      分享:php上傳經典源碼
      以下為引用的內容: function function_upload($name,$newname=,$dir=upload) { global $_FILES,$ext;

      共2頁上一頁12下一頁
      來源:模板無憂//所屬分類:PHP教程/更新時間:2009-09-03
      相關PHP教程