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

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

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

    一江春水向東流

    做一個(gè)有思想的人,期待與每一位熱愛(ài)思考的人交流,您的關(guān)注是對(duì)我最大的支持。

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      44 隨筆 :: 139 文章 :: 81 評(píng)論 :: 0 Trackbacks

    ?

    <? php
    /*
    ?*?分頁(yè)顯示類(lèi)
    ?*?PageItem.php v?1.0.0
    ?*?編程:Boban<boban@21php.com>
    ?*?討論:http://www.21php.com/forums/
    ?*?更新:2004-02-02
    ?*?說(shuō)明:
    ?*?1.?配合MYSQL數(shù)據(jù)庫(kù)使用
    ?*?2.?類(lèi)沒(méi)有提供連接數(shù)據(jù)庫(kù)的功能,需在外部建立數(shù)據(jù)庫(kù)連接。
    ?*?
    */
    /*
    ?*?使用方法:
    ?*?$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 ;? // ?默認(rèn)每頁(yè)顯示記錄數(shù),如果沒(méi)有設(shè)置,就使用默認(rèn)


    ????
    var ? $iMaxRecord ;? // 每頁(yè)記錄數(shù)
    ???? var ? $iTotal ;? // 記錄總數(shù)
    ???? var ? $sqlRecord ;? // ?獲取記錄的SQL查詢(xún)
    ???? var ? $iPages ;? // 總頁(yè)數(shù)
    ???? var ? $CPages ;? // 當(dāng)前頁(yè)數(shù)
    ???? /*
    ??*?構(gòu)造函數(shù)?--?初始化變量
    ??*?參數(shù):SQL查詢(xún)語(yǔ)句,將忽略LIMIT語(yǔ)句
    ??*?
    */

    ????
    function ?PageItem( $sql ? = ? "" )
    ????{?
    ????????
    // ?register_shutdown_function($this->_PageItem());
    ???????? $this -> SetMaxRecord( $this -> iDefaultRecords);
    ????????
    /*
    ???????*?解析SQL語(yǔ)句
    ???????*?
    */
    ????????
    if ?( $sql ? <> ? "" )?{
    ????????????
    list ( $sql )? = ? spliti ( " LIMIT " , ? $sql );? // ?去除LIMIT語(yǔ)句
    ???????????? $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;

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

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

    ????
    /*
    ?????*?統(tǒng)計(jì)匹配的記錄總數(shù)
    ?????*?
    */
    ????
    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 ;
    ????}?

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

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

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

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

    ????
    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();
    ????}?
    }?
    // ?類(lèi)結(jié)束

    ?> ???

    <?php
    /*
    ?* 分頁(yè)顯示類(lèi)
    ?* PageItem.php v 1.0.0
    ?* 編程:Boban<boban@21php.com>
    ?* 討論:http://www.21php.com/forums/
    ?* 更新:2004-02-02
    ?* 說(shuō)明:
    ?* 1. 配合MYSQL數(shù)據(jù)庫(kù)使用
    ?* 2. 類(lèi)沒(méi)有提供連接數(shù)據(jù)庫(kù)的功能,需在外部建立數(shù)據(jù)庫(kù)連接。
    ?* */
    /*
    ?* 使用方法:
    ?* $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; // 默認(rèn)每頁(yè)顯示記錄數(shù),如果沒(méi)有設(shè)置,就使用默認(rèn)


    ??? var $iMaxRecord; //每頁(yè)記錄數(shù)
    ??? var $iTotal; //記錄總數(shù)
    ??? var $sqlRecord; // 獲取記錄的SQL查詢(xún)
    ??? var $iPages; //總頁(yè)數(shù)
    ??? var $CPages; //當(dāng)前頁(yè)數(shù)
    ??? /*
    ? * 構(gòu)造函數(shù) -- 初始化變量
    ? * 參數(shù):SQL查詢(xún)語(yǔ)句,將忽略LIMIT語(yǔ)句
    ? * */

    ??? function PageItem($sql = "")
    ??? {
    ??????? // register_shutdown_function($this->_PageItem());
    ??????? $this->SetMaxRecord($this->iDefaultRecords);
    ??????? /*
    ?????? * 解析SQL語(yǔ)句
    ?????? * */
    ??????? if ($sql <> "") {
    ??????????? list($sql) = spliti("LIMIT", $sql); // 去除LIMIT語(yǔ)句
    ??????????? $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;
    ??? }
    ??? /*
    ???? * 析構(gòu)函數(shù) -- 暫時(shí)不可用
    ???? * */
    ??? function _PageItem()
    ??? {
    ??????? // $this->linkid = NULL;
    ??? }

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

    ??? /*
    ???? * 統(tǒng)計(jì)匹配的記錄總數(shù)
    ???? * */
    ??? 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;
    ??? }

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

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

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

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

    ??? 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();
    ??? }
    } // 類(lèi)結(jié)束

    ?>??

    posted on 2008-05-24 20:00 allic 閱讀(188) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): PHP+MySQL開(kāi)發(fā)
    主站蜘蛛池模板: 色多多www视频在线观看免费| 亚洲日本久久久午夜精品| 亚洲AV无码1区2区久久| 亚洲视频在线观看| 亚洲另类小说图片| 国产午夜亚洲精品| 色欲色欲天天天www亚洲伊| 特级av毛片免费观看| 黄色网页在线免费观看| 国产无遮挡无码视频免费软件 | 黄 色一级 成 人网站免费| av永久免费网站在线观看| 91精品国产免费久久国语麻豆| 久九九精品免费视频| 国产精品免费视频一区| 伊人亚洲综合青草青草久热| 亚洲美女视频网站| 亚洲精品天堂成人片AV在线播放| av网站免费线看| 19禁啪啪无遮挡免费网站| 国内自产少妇自拍区免费| 中文字幕亚洲电影| 亚洲第一精品电影网| 亚洲av成本人无码网站| 91精品成人免费国产| 男女超爽刺激视频免费播放| 成人亚洲综合天堂| 午夜亚洲www湿好大| 亚洲Av永久无码精品黑人| 精选影视免费在线 | 国产精彩免费视频| 亚洲一级特黄无码片| 亚洲精品mv在线观看| 日韩在线一区二区三区免费视频| 老汉精品免费AV在线播放| 国产精品免费视频一区| 青青草原精品国产亚洲av| 免费观看亚洲人成网站| 91精品免费高清在线| 亚洲?v无码国产在丝袜线观看| 日产亚洲一区二区三区|