http://expert.csdn.net/Expert/topic/1770/1770195.xml?temp=.225094
用的是MYSQL,但大致应差不多。

解决方案 »

  1.   

    给你转贴一个吧!
    pager.inc.php
    <?php
    //
    // +----------------------------------------------------------------------+
    // | 分页                                                                 |
    // | Authors: whxbb([email protected])                                  |
    // +----------------------------------------------------------------------+
    //
    // $Id: pager.class.php,v 1.0 2001/10/10 13:31:57 whxbb Exp $
    ///** 出错信息 */
    $PAGE_CLASS_ERROR = array( 1 => '3001:获取总纪录数失败',
                               2 => '3002:获取总纪录数失败',
                               5 => '3005:列表失败',
                               6 => '3006:列表失败',
                               7 => '3007:记录为空'
                             );
    /**
    * Purpose
    * 分页
    * @author:whxbb([email protected])
    * @version 0.1
    * @access public
    */class pager
    {
        /** 总纪录数 */
        var $total;
        /** 总页数 */
        var $totalpage;
        /** 当前页 */
        var $page ;
        /** 前页 */
        var $prev = 0;
        /** 后页 */
        var $next = 0;
        /** 每页显示 */
        var $items;
        /** 错误号 */
        var $errno = 0;
        /** 结果集 */
        var $result;
        function page()
        {
        }    function nextpage()
        {
            $this->next = $this->page + 1;
            if ($this->next > $this->totalpage)
                $this->next = 0;
        }    function prevpage()
        {
            $this->prev = $this->page - 1;
            if ($this->prev <= 0)
                $this->prev = 0;
        }    /**
         * 列出纪录
         * @param $sqlArr sql语句数组
         *                conn       数据库连结  
         *                fields  主语句      id, name, age
         *                table      表名        clients
         *                condition  查询条件    id >50 and name like '%y%'
         *                 order      排序方式    order by age desc
         * @param $items 每页显示的条数
         * @param $page 当前页码
         * @return 出错或没有纪录 false
         *         成功           关联数据,存贮纪录结果
         */
        function listn($sqlArr,$items,$page)
        {
            $this->items = $items;
            /** 得到总纪录数 */
            $this->getTotal($sqlArr);
            /** 得到总页数 */
            $this->totalpage = ceil($this->total / $this->items);        if ($page == 0 || $page == '')
                $page = 1;
            if ($page > $this->totalpage)
                $page = $this->totalpage;
            $this->page = $page;        $this->nextpage();
            $this->prevpage();        /** 获取分页查询语句 */
            $query = $this->gensql($sqlArr);        $stmt = @OCIParse($sqlArr['conn'], $query);
            if (!$stmt)
            {
                $this->errno = 5;
                return false;
            }
            if (!@OCIExecute($stmt))
            {
                $this->errno = 6;
                return false;
            }
            $i = 0;
            while(@OCIFetchInto($stmt, &$tmpArr[$i], OCI_ASSOC))
            {
                $arr[$i] = $tmpArr[$i];
                $i++;
            }        if ($i == 0)
            {
                $this->errno = 7;
                return false;
            }
            $this->result = $arr;
            @OCIFreeStatement($stmt);
            return true;
        }    /**
         * 得到纪录总数
         * @param $sqlArr
         * @see listn()
         * @access public
         */
        function getTotal($sqlArr)
        {
            $condition = $sqlArr['condition'];        if ($condition != ''){
                $condition  = " where ".$condition.' ';
            }        $query = "select count(*) from " .$sqlArr['table'].$condition;
            $stmt = @OCIParse($sqlArr['conn'], $query);
            if (!$stmt)
            {
                $this->errno = 1;
                return false;
            }
            if(!@OCIExecute($stmt))
            {
                $this->errno = 2;
                return false;
            }
            @OCIFetch($stmt);
            $this->total = @OCIResult($stmt, 1);
            @OCIFreeStatement($stmt);
            return true;
        }
        /**
         * 生成分页查询语句
         * @param $sqlArr   查询语句
         * @return string $query
         * @see listn()
         */
        function gensql($sqlArr) {
            $condition = $sqlArr['condition'];
            if ($condition != '') {
                $condition  = " where ".$condition.' ';
            }        $start = ($this->page - 1) * $this->items + 1;
            $end = $start + $this->items;        $query = " select ".$sqlArr['fields']." from ";
            $tmpQuery = $query.$sqlArr['table'].$condition.$order;
            $query = $query." (".$tmpQuery.") where rownum < $end "." minus ".$query." (".$tmpQuery.") where rownum < $start ";
            return $query;
        }    /**
         * 得到错误信息
         * @access public
         * @return error msg string or false
         */
        function errmsg()
        {
            global $PRIZE_CLASS_ERROR;
            
            if ($this->errno == 0)
                return false;
            else
                return $PRIZE_CLASS_ERROR[$this->errno];
        }
    }
    ?>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    下面是分页示例程序,看起来可能比较繁琐,但其实你只要用一下就会发现,"一切原来如此简单" :)
    example.php
    <?php
    $conn = ociplogon("test","123456","test123");
    include_once "pager.inc.php";
    ?><?php
    /** 分页测试开始 */// {{{ 初始分页对象
    $pager = new pager();
    /** 将 select id,name,age from test where age>20 order by id desc 拆分 */
    $sqlArr = array('conn' => $conn,              // 数据库连结
                    'fields' => " id,name,age ",  // 查询主语句
                    'table'  => "test",           // 表名
                    'condition' => " age>20 ",    // 查询条件
                    'order'     => " order by id desc " // 排序方式
                   );
    if (!$pager->listn($sqlArr,10,$page))  // 每页显示10条
    {
        $pager->errno = 10;
        die($pager->errmsg());
    }
        //}}}// {{{ 数据显示
    for( $i = 0; $i < count($pager->result); $i++)
    {
        $tmp = $pager->result[$i];
        echo " id:".$tmp['ID']."<br>";
        echo " name:".$tmp['NAME']."<br>";
        echo " age:".$tmp['AGE']."<hr>"
    }
        // }}}// {{{ 显示翻页链结
    echo $pager->page. " / ".$pager->totalpage." 共 ".$pager->total. "条记录 ";
    if ($pager->prev != 0)
        echo " <a href=$PHP_SELF?page=".$pager->prev.">上一页</a> ";
    else
        echo " 上一页 ";if ($pager->next != 0)
        echo " <a href=$PHP_SELF?page=".$pager->next.">下一页</a> ";
    else
        echo " 下一页 ";
    // }}}
    ?><?@OCILogoff($conn)?>好运!
      

  2.   

    使用php+mysql做的分页显示
    看看吧,应该差不多的啦<?php 
    //使用分页技术
    if($offset)
    {
      $preoffset=$offset-10;
      print("<a href=\"$PHP_SELF?offset=$preoffset\">上一页</a>&nbsp;\n");
      }
      //计算总共需要的页数
      $page_cnt=ceil($num/10);
      //显示所有页的链接
      for($i=1;$i<=$page_cnt;$i++)
      {
      $page_offset=10*$i-10;
      print("<a href=\"$PHP_SELF?offset=$page_offset\">$i</a>&nbsp;\n");
      }
      //检查是否是最后一页
      if($page_cnt!=0&&(($offset+10)/10)!=$page_cnt)
      {
      $backoffset=$offset+10;
      print("<a href=\"$PHP_SELF?offset=$backoffset\">下一页</a>&nbsp;\n");
      }
    ?>上面是源代码,还有中文注释呢!!!
    呵呵^
      

  3.   

    //*来自冬冬的整理类*//
    <?php
    class Page
    {
        var $page = 1;              //当前页数
        var $maxLine = 20;           //最大行数
        var $total;             //总记录数
        var $totalPages;        //总页数
        var $qStr = array();    //附加链接的query strings
        var $offset;
        
        function Page($page,$maxline,$totalnum)
        {
            
            
            $this ->total =$totalnum;
            $page = intval($page);   //intval变数转成整数型态
            if (empty($page)) {
                $this->page = 1;
            } elseif ($page <= 0) {
                $this->page = 1;
            } else {
                $this->page = $page;
            }
            //if($page>ceil($totalnum/$maxline))$this->page=1;  //ceil计算大于指定数的最小整数    
            $this->maxLine = $maxline;
            
        } // end func    function SetQstr($varname, $value=null)
        {
            if (is_array($varname)) {    //is_array判断变数型态是否为阵列型态。
                $this->qStr = $varname;
            } else {
                $this->qStr[$varname] = $value;
            }
        } // end func
        function Run()
        {            
            if ($this->maxLine != 0) {
                $this->totalPages = ceil($this->total/$this->maxLine);  //ceil计算大于指定数的最小整数
            } else {
                $this->totalPages = 0;
            }
            if ($this->page > $this->totalPages && $this->totalPages!=0) {
                $this->page = $this->totalPages;
                //$this->page = 1;
            }
            $this->offset = isset($this->page)?($this->page-1)*20 : 0 ;
            
        } // end func
        function ThePage()
        {
            if ($this->totalPages == 0) {
                return '';
            }
            return "第 ".$this->page." 页 / 共 ".$this->totalPages." 页";
        } // end func    function TurnPage()
        {
            if ($this->total == 0) {
                return '本页没有记录';
            }
            if ($this->total < $this->maxLine) {
                return '目前只有一页';
            }        $qstr = $this->getQstr($this->qStr);        $str = '';
            if ($this->page == 1) {
                $str .= '首页 上页 ';
            } else {
                $str .= "<a href=$PHP_SELF?page=1$qstr>首页</a> ";
                $str .= "<a href=$PHP_SELF?page=".($this->page - 1)."$qstr>上页</a> ";
            }
            
            if ($this->page == $this->totalPages) {
                $str .= '下页 尾页';
            } else {
                $str .= "<a href=$PHP_SELF?page=".($this->page + 1)."$qstr>下页</a> ";
                $str .= "<a href=$PHP_SELF?page=".$this->totalPages."$qstr>尾页</a>";
            }        return $str;
        } // end func
        function JumpPage()
        {
            if ($this->totalPages == 0) {
                return '';
            }        $qstr = $this->getQstr($this->qStr);        $str = "<table border=0 cellpadding=0 cellspacing=0><form method=post action=$PHP_SELF?$qstr><tr><td>跳转到<input type=text name=page value=".$this->page." size=1>页<INPUT TYPE=submit value=go></td></tr></form></table>";
            return $str;
        } // end func    function PointPage()
        {
            if ($this->total == 0) {
                return '本页没有记录';
            }
            if ($this->total < $this->maxLine) {
                return '目前只有一页';
            }        $qstr = $this->getQstr($this->qStr);        $start = $this->getStartPoint($this->page);
            $end = $this->getEndPoint($this->page, $this->totalPages);        if ($start != 1) {
                $str .= "<a href=$PHP_SELF?page=".($start-1)."$qstr><<</a> ";
            }
            
            for ($i=$start;$i<=$end ;$i++ ) {
                if ($i == $this->page) {
                    $str .= "<b> [$i] </b> ";
                } else {
                    $str .= " <a href=$PHP_SELF?page=$i$qstr>  $i  </a>  ";
                }            
            }
            if ($end < $this->totalPages) {
                $str .= "<a href=$PHP_SELF?page=".($end+1)."$qstr>>></a>";
            }
            return $str;        
        } // end func
        
        function getQstr($qstr)
        {
            $str = '';
            if (is_array($qstr) && count($qstr)) {    //is_array判断变数型态是否为阵列型态。count计算变数或阵列中的元素个数
                foreach ($qstr as $name => $value) {
                    $str .= '&'.$name.'='.$value;
                }
            }
            return $str;
        } // end func    function getOffset()
        {
            return ($this->page-1) * $this->maxLine;
        } // end func
        function getTotal()
        {
            return $this->total;
        } // end func
        function getStartPoint($current)
        {
            while ($current) {
                if ($current ==1) {
                    return $current;
                }
                if (substr($current, -1) =='0') {   //substr取部份字串
                    return $current;
                }
                $current--;
            }        
        } // end func    function getEndPoint($current, $total)
        {
            while ($current) {
                if ($current == $total) {
                    return $current;
                }
                if (substr($current, -1) =='9') {  //substr取部份字串
                    return $current;
                }
                $current++;
            }        
        } // end func} // end class
    ?>
      

  4.   

    captain208能否将具体调用实例写一个谢谢