<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一江春水向東流

    做一個有思想的人,期待與每一位熱愛思考的人交流,您的關注是對我最大的支持。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      44 隨筆 :: 139 文章 :: 81 評論 :: 0 Trackbacks

    ?

    <? php
    /*
    ?*?分頁顯示類
    ?*?PageItem.php v?1.0.0
    ?*?編程:Boban<boban@21php.com>
    ?*?討論:http://www.21php.com/forums/
    ?*?更新:2004-02-02
    ?*?說明:
    ?*?1.?配合MYSQL數據庫使用
    ?*?2.?類沒有提供連接數據庫的功能,需在外部建立數據庫連接。
    ?*?
    */
    /*
    ?*?使用方法:
    ?*?$sql?=?"select?*?from?news?limit?0,10";
    ?*?$hdc?=?new?PageItem($sql);
    ?*?echo?$hdc->myPageItem();
    ?*?$arrRecords?=?$hdc->ReadList();
    ?*?
    */
    if ?( ! defined ( " __PAGEITEM__ " ))?{
    ????
    define ( " __PAGEITEM__ " , ? 1 );
    }?
    else ?{
    ????
    exit ( 3 );
    }?

    class ?PageItem?{
    ????
    var ? $iDefaultRecords ? = ? 10 ;? // ?默認每頁顯示記錄數,如果沒有設置,就使用默認


    ????
    var ? $iMaxRecord ;? // 每頁記錄數
    ???? var ? $iTotal ;? // 記錄總數
    ???? var ? $sqlRecord ;? // ?獲取記錄的SQL查詢
    ???? var ? $iPages ;? // 總頁數
    ???? var ? $CPages ;? // 當前頁數
    ???? /*
    ??*?構造函數?--?初始化變量
    ??*?參數:SQL查詢語句,將忽略LIMIT語句
    ??*?
    */

    ????
    function ?PageItem( $sql ? = ? "" )
    ????{?
    ????????
    // ?register_shutdown_function($this->_PageItem());
    ???????? $this -> SetMaxRecord( $this -> iDefaultRecords);
    ????????
    /*
    ???????*?解析SQL語句
    ???????*?
    */
    ????????
    if ?( $sql ? <> ? "" )?{
    ????????????
    list ( $sql )? = ? spliti ( " LIMIT " , ? $sql );? // ?去除LIMIT語句
    ???????????? $this -> sqlRecord? = ? trim ( $sql );
    ????????????
    list ( , ? $sql )? = ? spliti ( " FROM " , ? $sql );
    ????????????
    $sql ? = ? trim ( $sql );
    ???
    if ( preg_match ?( " /\bGROUP\b?\bBY\b/i " , ? $sql ))
    ???{
    ????
    // echo?"HAVE?GROUP?BY";
    ???? if ( preg_match ?( " /\bHAVING\b/i " , ? $sql ))? list ( , $field )? = ? spliti

    (
    " HAVING " , $sql );
    ????
    list ( $field )? = ? spliti ( ' ? ' , trim ( $field ));
    ????
    // echo?$field;
    ???? $this -> iTotal? = ? $this -> CountRecord( " SELECT?$field,COUNT(DISTINCT?$field)?

    AS?cnt?FROM?
    " ? . ? $sql , 2 );
    ???}
    ???
    else ? $this -> iTotal? = ? $this -> CountRecord( " SELECT?COUNT(*)?AS?cnt?FROM? " ? . ?

    $sql , 1 );
    ????????}?
    ????????
    $this -> iPages? = ? ceil ( $this -> iTotal? / ? $this -> iMaxRecord);
    ????????
    $this -> CPages? = ? $_REQUEST [ ' page ' ];
    ????????
    if ?( $this -> CPages? <= ? 0 )? $this -> CPages? = ? 1 ;
    ????????
    if ?( $this -> CPages? > ? $this -> iPages)? $this -> CPages? = ? $this -> iPages;
    ????????
    // echo?"SELECT?COUNT(*)?AS?cnt?FROM?"?.?$sql;
    ??//echo?$this->iTotal;

    ????}?
    ????
    /*
    ?????*?析構函數?--?暫時不可用
    ?????*?
    */
    ????
    function ?_PageItem()
    ????{?
    ????????
    // ?$this->linkid?=?NULL;
    ????}?

    ????
    function ?SetMaxRecord( $cnt )
    ????{
    ????????
    $this -> iMaxRecord? = ? $cnt ;
    ????}?

    ????
    /*
    ?????*?統計匹配的記錄總數
    ?????*?
    */
    ????
    function ?CountRecord( $sql , $type )
    ????{
    ??
    // echo?$sql;
    ?? if ( $type ? == ? 1 )
    ??{
    ???
    if ?(( $records ? = ? mysql_query ( $sql ))? && ?( $record ? = ? mysql_fetch_assoc

    (
    $records )))?{
    ????
    return ? $record [ ' cnt ' ];
    ???}?
    else ? return ? 0 ;
    ??}
    ??
    elseif ( $type ? == ? 2 )
    ??{
    ???
    if ( $records ? = ? mysql_query ( $sql ))
    ????
    return ? mysql_affected_rows ();
    ??}
    ????}
    ?
    /* ?
    ??*?讀取記錄
    ??*?
    */
    ?
    function ?ReadList()
    ?{
    ??
    $ret ? = ? array ();
    ??
    $this -> sqlRecord .= " ?LIMIT? " . ( $this -> CPages - 1 ) * $this -> iMaxRecord . " , " . $this -

    > iMaxRecord;
    ??
    $records ? = ? mysql_query ( $this -> sqlRecord);
    ??
    if ( ! $records )? return ;
    ??
    while ( $record ? = ? mysql_fetch_array ( $records ))
    ??{
    ???
    $ret []? = ? $record ;
    ??}
    ??
    return ? $ret ;
    ?}

    ????
    function ?LinktoPage( $page , ? $msg )
    ????{
    ????????
    $link ? = ? $this -> PageUrl( $page );
    ????????
    return ? " <A?href=\ " $link \ " >$msg</A>\n " ;
    ????}?
    ????
    function ?PageUrl( $page )
    ????{
    ????????
    $phpself ? = ? " http:// " ? . ? $_SERVER [ ' SERVER_NAME ' ]? . ? $_SERVER [ ' PHP_SELF ' ];
    ????????
    $querystring ? = ? $_SERVER [ ' QUERY_STRING ' ];
    ????????
    $querystring ? = ? preg_replace ( " /page=[0-9]*&?/i " , ? "" , ? $querystring );
    ????????
    $link ? = ? $phpself ? . ? " ?page=$page& " ? . ? $querystring ;
    ????????
    return ? $link ;
    ????}?

    ????
    /* ?
    ??*?顯示當前頁及總頁數???
    ??*?
    */
    ????
    function ?PageNav()
    ????{
    ????????
    echo ? " " ? . ? $this -> CPages? . ? " 頁/共 " ? . ? $this -> iPages? . ? " " ;
    ????}?

    ????
    /* ?
    ???*?顯示翻頁按鈕,包括首頁、下頁、上頁、未頁
    ???*?
    */

    ????
    function ?PageButton()
    ????{
    ????????
    if ?( $this -> CPages? > ? 1 )?{
    ????????????
    echo ? $this -> LinktoPage( 1 , ? " 首頁 " );
    ????????????
    echo ? " ?|? " ;
    ????????????
    echo ? $this -> LinktoPage( $this -> CPages - 1 , ? " 上一頁 " );
    ????????}?
    else ?{
    ????????????
    echo ? " 首頁?|?上一頁 " ;
    ????????}?

    ????????
    if ?( $this -> CPages? < ? $this -> iPages)?{
    ????????????
    echo ? " ?|? " ;
    ????????????
    echo ? $this -> LinktoPage( $this -> CPages? + ? 1 , ? " 下一頁 " );
    ????????????
    echo ? " ?|? " ;
    ????????????
    echo ? $this -> LinktoPage( $this -> iPages , ? " 首頁 " );
    ????????}?
    else ?{
    ????????????
    echo ? " ?|?下一頁?|?尾頁 " ;
    ????????}?
    ????}
    ????
    /* ?
    ???*?顯示跳轉頁選擇框
    ???*?
    */

    ????
    function ?SelectItem()
    ????{
    ????????
    echo ? " 跳到第<SELECT?name='topage'?size='1'?

    onchange='window.location=this.value'>\n
    " ;
    ????????
    for ( $i ? = ? 1 ; $i ? <= ? $this -> iPages; $i ++ )?{
    ????????????
    if ?( $this -> CPages? == ? $i )
    ????????????????
    $extra ? = ? " selected " ;
    ????????????
    else
    ????????????????
    $extra ? = ? "" ;
    ????????????
    echo ? " <OPTION?VALUE=' " ? . ? $this -> PageUrl( $i )? . ? " '?

    $extra>$i</OPTION>
    " ;
    ????????}?
    ????????
    echo ? " </SELECT>\n " ;
    ????}

    ????
    /*
    ?????*?一次性顯示所有按鈕組件
    ?????*?
    */
    ????
    function ?myPageItem()
    ????{
    ????????
    $this -> PageButton();
    ????????
    $this -> SelectItem();
    ????????
    $this -> PageNav();
    ????}?
    }?
    // ?類結束

    ?> ???

    <?php
    /*
    ?* 分頁顯示類
    ?* PageItem.php v 1.0.0
    ?* 編程:Boban<boban@21php.com>
    ?* 討論:http://www.21php.com/forums/
    ?* 更新:2004-02-02
    ?* 說明:
    ?* 1. 配合MYSQL數據庫使用
    ?* 2. 類沒有提供連接數據庫的功能,需在外部建立數據庫連接。
    ?* */
    /*
    ?* 使用方法:
    ?* $sql = "select * from news limit 0,10";
    ?* $hdc = new PageItem($sql);
    ?* echo $hdc->myPageItem();
    ?* $arrRecords = $hdc->ReadList();
    ?* */
    if (!defined("__PAGEITEM__")) {
    ??? define("__PAGEITEM__", 1);
    } else {
    ??? exit(3);
    }

    class PageItem {
    ??? var $iDefaultRecords = 10; // 默認每頁顯示記錄數,如果沒有設置,就使用默認


    ??? var $iMaxRecord; //每頁記錄數
    ??? var $iTotal; //記錄總數
    ??? var $sqlRecord; // 獲取記錄的SQL查詢
    ??? var $iPages; //總頁數
    ??? var $CPages; //當前頁數
    ??? /*
    ? * 構造函數 -- 初始化變量
    ? * 參數:SQL查詢語句,將忽略LIMIT語句
    ? * */

    ??? function PageItem($sql = "")
    ??? {
    ??????? // register_shutdown_function($this->_PageItem());
    ??????? $this->SetMaxRecord($this->iDefaultRecords);
    ??????? /*
    ?????? * 解析SQL語句
    ?????? * */
    ??????? if ($sql <> "") {
    ??????????? list($sql) = spliti("LIMIT", $sql); // 去除LIMIT語句
    ??????????? $this->sqlRecord = trim($sql);
    ??????????? list(, $sql) = spliti("FROM", $sql);
    ??????????? $sql = trim($sql);
    ?? if(preg_match ("/\bGROUP\b \bBY\b/i", $sql))
    ?? {
    ??? //echo "HAVE GROUP BY";
    ??? if(preg_match ("/\bHAVING\b/i", $sql)) list(,$field) = spliti

    ("HAVING",$sql);
    ??? list($field) = spliti(' ',trim($field));
    ??? //echo $field;
    ??? $this->iTotal = $this->CountRecord("SELECT $field,COUNT(DISTINCT $field)

    AS cnt FROM " . $sql,2);
    ?? }
    ?? else $this->iTotal = $this->CountRecord("SELECT COUNT(*) AS cnt FROM " .

    $sql,1);
    ??????? }
    ??????? $this->iPages = ceil($this->iTotal / $this->iMaxRecord);
    ??????? $this->CPages = $_REQUEST['page'];
    ??????? if ($this->CPages <= 0) $this->CPages = 1;
    ??????? if ($this->CPages > $this->iPages) $this->CPages = $this->iPages;
    ??????? //echo "SELECT COUNT(*) AS cnt FROM " . $sql;
    ? //echo $this->iTotal;
    ??? }
    ??? /*
    ???? * 析構函數 -- 暫時不可用
    ???? * */
    ??? function _PageItem()
    ??? {
    ??????? // $this->linkid = NULL;
    ??? }

    ??? function SetMaxRecord($cnt)
    ??? {
    ??????? $this->iMaxRecord = $cnt;
    ??? }

    ??? /*
    ???? * 統計匹配的記錄總數
    ???? * */
    ??? function CountRecord($sql,$type)
    ??? {
    ? //echo $sql;
    ? if($type == 1)
    ? {
    ?? if (($records = mysql_query($sql)) && ($record = mysql_fetch_assoc

    ($records))) {
    ??? return $record['cnt'];
    ?? } else return 0;
    ? }
    ? elseif($type == 2)
    ? {
    ?? if($records = mysql_query($sql))
    ??? return mysql_affected_rows();
    ? }
    ??? }
    ?/*
    ? * 讀取記錄
    ? * */
    ?function ReadList()
    ?{
    ? $ret = array();
    ? $this->sqlRecord.=" LIMIT ".($this->CPages-1)*$this->iMaxRecord.",".$this-

    >iMaxRecord;
    ? $records = mysql_query($this->sqlRecord);
    ? if(!$records) return;
    ? while($record = mysql_fetch_array($records))
    ? {
    ?? $ret[] = $record;
    ? }
    ? return $ret;
    ?}

    ??? function LinktoPage($page, $msg)
    ??? {
    ??????? $link = $this->PageUrl($page);
    ??????? return "<A href=\"$link\">$msg</A>\n";
    ??? }
    ??? function PageUrl($page)
    ??? {
    ??????? $phpself = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
    ??????? $querystring = $_SERVER['QUERY_STRING'];
    ??????? $querystring = preg_replace("/page=[0-9]*&?/i", "", $querystring);
    ??????? $link = $phpself . "?page=$page&" . $querystring;
    ??????? return $link;
    ??? }

    ??? /*
    ? * 顯示當前頁及總頁數??
    ? * */
    ??? function PageNav()
    ??? {
    ??????? echo "第" . $this->CPages . "頁/共" . $this->iPages . "頁";
    ??? }

    ??? /*
    ?? * 顯示翻頁按鈕,包括首頁、下頁、上頁、未頁
    ?? * */

    ??? function PageButton()
    ??? {
    ??????? if ($this->CPages > 1) {
    ??????????? echo $this->LinktoPage(1, "首頁");
    ??????????? echo " | ";
    ??????????? echo $this->LinktoPage($this->CPages-1, "上一頁");
    ??????? } else {
    ??????????? echo "首頁 | 上一頁";
    ??????? }

    ??????? if ($this->CPages < $this->iPages) {
    ??????????? echo " | ";
    ??????????? echo $this->LinktoPage($this->CPages + 1, "下一頁");
    ??????????? echo " | ";
    ??????????? echo $this->LinktoPage($this->iPages, "首頁");
    ??????? } else {
    ??????????? echo " | 下一頁 | 尾頁";
    ??????? }
    ??? }
    ??? /*
    ?? * 顯示跳轉頁選擇框
    ?? * */

    ??? function SelectItem()
    ??? {
    ??????? echo "跳到第<SELECT name='topage' size='1'

    onchange='window.location=this.value'>\n";
    ??????? for($i = 1;$i <= $this->iPages;$i++) {
    ??????????? if ($this->CPages == $i)
    ??????????????? $extra = "selected";
    ??????????? else
    ??????????????? $extra = "";
    ??????????? echo "<OPTION VALUE='" . $this->PageUrl($i) . "'

    $extra>$i</OPTION>";
    ??????? }
    ??????? echo "</SELECT>\n";
    ??? }

    ??? /*
    ???? * 一次性顯示所有按鈕組件
    ???? * */
    ??? function myPageItem()
    ??? {
    ??????? $this->PageButton();
    ??????? $this->SelectItem();
    ??????? $this->PageNav();
    ??? }
    } // 類結束

    ?>??

    posted on 2008-05-24 20:00 allic 閱讀(188) 評論(0)  編輯  收藏 所屬分類: PHP+MySQL開發
    主站蜘蛛池模板: 青青草原1769久久免费播放| 两性色午夜免费视频| 在线免费观看亚洲| 亚洲熟妇无码另类久久久| 国产V片在线播放免费无码| 亚洲国产精品毛片av不卡在线| 精品在线免费视频| 免费人成网站在线播放| 国产亚洲精品美女久久久久 | 亚洲福利一区二区| 亚洲免费福利视频| 在线观看日本亚洲一区| 永久免费AV无码网站在线观看| 亚洲第一成年网站视频 | 亚洲精品成人图区| AV大片在线无码永久免费| 亚洲一区在线观看视频| 麻豆国产VA免费精品高清在线 | 久久久久亚洲国产AV麻豆| 国产yw855.c免费视频| WWW国产成人免费观看视频| 久久精品国产精品亚洲蜜月| 国产成人精品免费视频大全麻豆| 亚洲人配人种jizz| 99久久久国产精品免费牛牛四川| 亚洲精品人成电影网| 四虎影院免费视频| 一日本道a高清免费播放| 亚洲av日韩av高潮潮喷无码 | 热99re久久免费视精品频软件| 国产精品亚洲一区二区三区久久| 中文字幕亚洲无线码| 国产偷国产偷亚洲高清人| 亚洲夜夜欢A∨一区二区三区| 24小时日本电影免费看| 日产亚洲一区二区三区| 成人毛片免费观看视频| 精品国产福利尤物免费| 亚洲国产综合精品| 亚洲国产精品自产在线播放| 99爱在线精品视频免费观看9 |