晓风的世界

程序生活每一天

用户操作
[即时聊天] [发私信] [加为好友]
testboyID:lgjlry
53234次访问,排名2126(-2),好友11人,关注者12人。
网站开发,数据库开发管理行业。php ,seo优化
lgjlry的文章
原创 192 篇
翻译 0 篇
转载 45 篇
评论 17 篇
testboy的公告
最近评论
周兴龙:我的联系电话是:0931-2937406(407)
周兴龙:请问发表四甲基乙二胺的是哪一位啊,怎么联系啊
爱不厌诈:肥龙龙,你的这篇文章太有帮助了,谢谢!http://www.zdh8.cn
QQ快乐大本营:QQ交易|免费QQ|QQ空间|QQ互踩|QQ技术|QQ模块|精品软件|PS制作交流|QQ工具与你共创QQ家园



http://yl8.5d6d.com/

QQ快乐大本营:QQ交易|免费QQ|QQ空间|QQ互踩|QQ技术|QQ模块|精品软件|PS制作交流|QQ工具与你共创QQ家园



http://yl8.5d6d.com/

文章分类
收藏
    相册
    年轻的周总理
    周恩来
    老师和朋友
    captain(RSS)
    ccjj
    chedong(RSS)
    kwanl
    架构设计
    程序人生(RSS)
    邹建(RSS)
    郝培强
    网络
    厦门书生(RSS)
    相关report service 的资料
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 php类收集收藏

    新一篇: 两个日期类 php类收集 | 旧一篇: 数据库设计范式深入浅出

    <?php
    // +----------------------------------------------------------------------+
    // | PHP Version 4                                     |
    // +----------------------------------------------------------------------+
    // | Copyright (c) 1997-2002 The PHP Group                     |
    // +----------------------------------------------------------------------+
    // | This source file is subject to version 2.02 of the PHP license,     |
    // | that is bundled with this package in the file LICENSE, and is     |
    // | available at through the world-wide-web at                   |
    // | [url]http://www.php.net/license/2_02.txt.[/url]                       |
    // | If you did not receive a copy of the PHP license and are unable to   |
    // | obtain it through the world-wide-web, please send a note to       |
    // | [email]license@php.net[/email] so we can mail you a copy immediately.           |
    // +----------------------------------------------------------------------+
    // | Authors: Richard Heyes <[email]richard@phpguru.org[/email]>                 |
    // +----------------------------------------------------------------------+


    /**
    * Pager class
    *
    * Handles paging a set of data. For usage see the example.php provided.
    *
    */

    class Pager {

      
    /**
      * Current page
      * @var integer
      
    */
      
    var $_currentPage;

      
    /**
      * Items per page
      * @var integer
      
    */
      
    var $_perPage;

      
    /**
      * Total number of pages
      * @var integer
      
    */
      
    var $_totalPages;

      
    /**
      * Item data. Numerically indexed array...
      * @var array
      
    */
      
    var $_itemData;

      
    /**
      * Total number of items in the data
      * @var integer
      
    */
      
    var $_totalItems;

      
    /**
      * Page data generated by this class
      * @var array
      
    */
      
    var $_pageData;

      
    /**
      * Constructor
      *
      * Sets up the object and calculates the total number of items.
      *
      * @param $params An associative array of parameters This can contain:
      *             currentPage   Current Page number (optional)
      *             perPage     Items per page (optional)
      *             itemData     Data to page
      
    */
      
    function pager($params = array())
      {
        
    global $HTTP_GET_VARS;

        
    $this->_currentPage = max((int)@$HTTP_GET_VARS['pageID'], 1);
        
    $this->_perPage   = 8;
        
    $this->_itemData   = array();

        
    foreach ($params as $name => $value) {
            
    $this->{'_' . $name= $value;
        }

        
    $this->_totalItems = count($this->_itemData);
      }

      
    /**
      * Returns an array of current pages data
      *
      * @param $pageID Desired page ID (optional)
      * @return array Page data
      
    */
      
    function getPageData($pageID = null)
      {
        
    if (isset($pageID)) {
            
    if (!empty($this->_pageData[$pageID])) {
              
    return $this->_pageData[$pageID];
            } 
    else {
              
    return FALSE;
            }
        }

        
    if (!isset($this->_pageData)) {
            
    $this->_generatePageData();
        }

        
    return $this->getPageData($this->_currentPage);
      }

      
    /**
      * Returns pageID for given offset
      *
      * @param $index Offset to get pageID for
      * @return int PageID for given offset
      
    */
      
    function getPageIdByOffset($index)
      {
        
    if (!isset($this->_pageData)) {
            
    $this->_generatePageData();
        }

        
    if (($index % $this->_perPage) > 0) {
            
    $pageID = ceil((float)$index / (float)$this->_perPage);
        } 
    else {
            
    $pageID = $index / $this->_perPage;
        }

        
    return $pageID;
      }

      
    /**
      * Returns offsets for given pageID. Eg, if you
      * pass it pageID one and your perPage limit is 10
      * it will return you 1 and 10. PageID of 2 would
      * give you 11 and 20.
      *
      * @params pageID PageID to get offsets for
      * @return array First and last offsets
      
    */
      
    function getOffsetByPageId($pageid = null)
      {
        
    $pageid = isset($pageid? $pageid : $this->_currentPage;
        
    if (!isset($this->_pageData)) {
            
    $this->_generatePageData();
        }

        
    if (isset($this->_pageData[$pageid])) {
            
    return array(($this->_perPage * ($pageid - 1)) + 1, min($this->_totalItems, $this->_perPage * $pageid));
        } 
    else {
            
    return array(0,0);
        }
      }

      
    /**
      * Returns back/next and page links
      *
      * @param $back_html HTML to put inside the back link
      * @param $next_html HTML to put inside the next link
      * @return array Back/pages/next links
      
    */
      
    function getLinks($back_html = '<< Back', $next_html = 'Next >>')
      {
        
    $url   = $this->_getLinksUrl();
        
    $back = $this->_getBackLink($url, $back_html);
        
    $pages = $this->_getPageLinks($url);
        
    $next = $this->_getNextLink($url, $next_html);

        
    return array($back, $pages, $next, 'back' => $back, 'pages' => $pages, 'next' => $next);
      }

      
    /**
      * Returns number of pages
      *
      * @return int Number of pages
      
    */
      
    function numPages()
      {
        
    return $this->_totalPages;
      }

      
    /**
      * Returns whether current page is first page
      *
      * @return bool First page or not
      
    */
      
    function isFirstPage()
      {
        
    return ($this->_currentPage == 1);
      }

      
    /**
      * Returns whether current page is last page
      *
      * @return bool Last page or not
      
    */
      
    function isLastPage()
      {
        
    return ($this->_currentPage == $this->_totalPages);
      }

      
    /**
      * Returns whether last page is complete
      *
      * @return bool Last age complete or not
      
    */
      
    function isLastPageComplete()
      {
        
    return !($this->_totalItems % $this->_perPage);
      }

      
    /**
      * Calculates all page data
      
    */
      
    function _generatePageData()
      {
        
    $this->_totalItems = count($this->_itemData);
        
    $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
        
    $i = 1;
        
    if (!empty($this->_itemData)) {
            
    foreach ($this->_itemData as $value) {
              
    $this->_pageData[$i][] = $value;
              
    if (count($this->_pageData[$i]) >= $this->_perPage) {
                
    $i++;
              }
            }
        } 
    else {
            
    $this->_pageData = array();
        }
      }

      
    /**
      * Returns the correct link for the back/pages/next links
      *
      * @return string Url
      
    */
      
    function _getLinksUrl()
      {
        
    global $HTTP_SERVER_VARS;

        
    // Sort out query string to prevent messy urls
        $querystring = array();
        
    if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
            
    $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);         
            
    for ($i = 0, $cnt = count($qs); $i < $cnt$i++) {
              
    list($name, $value= explode('=', $qs[$i]);
              
    if ($name != 'pageID') {
                
    $qs[$name= $value;
              }
              
    unset($qs[$i]);
            }
        }
      
    if(is_array($qs)){
            
    foreach ($qs as $name => $value) {
              
    $querystring[] = $name . '=' . $value;
            }   
      }
        
    return $HTTP_SERVER_VARS['SCRIPT_NAME'. '?' . implode('&', $querystring. (!empty($querystring? '&' : ''. 'pageID=';
      }

      
    /**
      * Returns back link
      *
      * @param $url URL to use in the link
      * @param 上一篇     目录     下一篇 HTML to use as the link
      * @return string The link
      
    */
      
    function _getBackLink($url, 上一篇     目录     下一篇 = '<< Back')
      {
        
    // Back link
        if ($this->_currentPage > 1) {
            
    $back = '<a href="' . $url . ($this->_currentPage - 1. '">' . 上一篇     目录     下一篇 . '</a>';
        } 
    else {
            
    $back = '';
        }
        
        
    return $back;
      }

      
    /**
      * Returns pages link
      *
      * @param $url URL to use in the link
      * @return string Links
      
    */
      
    function _getPageLinks($url)
      {
        
    // Create the range
        $params['itemData'= range(1, max(1, $this->_totalPages));
        
    $pager =& new Pager($params);
        上一篇     目录     下一篇s 
    = $pager->getPageData($pager->getPageIdByOffset($this->_currentPage));

        
    for ($i=0$i<count(上一篇     目录     下一篇s); $i++) {
            
    if (上一篇     目录     下一篇s[$i!= $this->_currentPage) {
              上一篇     目录     下一篇s[
    $i= '<a href="' . $this->_getLinksUrl() . 上一篇     目录     下一篇s[$i. '">' . 上一篇     目录     下一篇s[$i. '</a>';
            }
        }

        
    return implode(' ', 上一篇     目录     下一篇s);
      }

      
    /**
      * Returns next link
      *
      * @param $url URL to use in the link
      * @param 上一篇     目录     下一篇 HTML to use as the link
      * @return string The link
      
    */
      
    function _getNextLink($url, 上一篇     目录     下一篇 = 'Next >>')
      {
        
    if ($this->_currentPage < $this->_totalPages) {
            
    $next = '<a href="' . $url . ($this->_currentPage + 1. '">' . 上一篇     目录     下一篇 . '</a>';
        } 
    else {
            
    $next = '';
        }

        
    return $next;
      }
    }

    ?>
    <?php
    //
    // +----------------------------------------------------------------------+
    // | 分页类                                           |
    // +----------------------------------------------------------------------+
    // | Copyright (c) 2001 NetFish Software                       |
    // |                                               |
    // | Author: whxbb([email]whxbbh@21cn.com[/email])                           |
    // +----------------------------------------------------------------------+
    //
    // $Id: pager.class.php,v 0.1 2001/8/2 13:18:13 yf Exp $
    //
    // 禁止直接访问该页面

    if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "pager.class.php") {
      
    header("HTTP/1.0 404 Not Found");
    }
    /**
    * 分页类
    * Purpose
    * 分页
    *
    * @author : whxbb([email]whxbb@21cn.com[/email])
    * @version : 0.1
    * @date   : 2001/8/2
    */
    class Pager
    {
      
    /** 总信息数 */
      
    var $infoCount;
      
    /** 总页数 */
      
    var $pageCount;
      
    /** 每页显示条数 */
      
    var $items;
      
    /** 当前页码 */
      
    var $pageNo;
      
    /** 查询的起始位置 */
      
    var $startPos;
      
    var $nextPageNo;
      
    var $prevPageNo;
      
      
    function Pager($infoCount, $items, $pageNo)
      {
        
    $this->infoCount = $infoCount;
        
    $this->items   = $items;
        
    $this->pageNo   = $pageNo;
        
    $this->pageCount = $this->GetPageCount();
        
    $this->AdjustPageNo();
        
    $this->startPos = $this->GetStartPos();
      }
      
    function AdjustPageNo()
      {
        
    if($this->pageNo == '' || $this->pageNo < 1)
            
    $this->pageNo = 1;
        
    if ($this->pageNo > $this->pageCount)
            
    $this->pageNo = $this->pageCount;
      }
      
    /**
      * 下一页
      
    */
      
    function GoToNextPage()
      {
        
    $nextPageNo = $this->pageNo + 1;
        
    if ($nextPageNo > $this->pageCount)
        {
            
    $this->nextPageNo = $this->pageCount;
            
    return false;
        }
        
    $this->nextPageNo = $nextPageNo;
        
    return true;
      }
      
    /**
      * 上一页
      
    */
      
    function GotoPrevPage()
      {
        
    $prevPageNo = $this->pageNo -