<?
/**********分页参数设置***************/
$page=(!isset($_GET[page])) ? 1 : $_GET[page]; 
$pagesize=2;
$start=($page-1)*$pagesize;
$end=$page*$pagesize;
/**********分页参数设置***************/ $result_nums0=tep_db_query($query_nums0);
$result_array_nums0=tep_db_fetch_array($result_nums0);
$numrows0=$result_array_nums0['nums'];

//$numrows0=count($result_nums0);
//$numrows0=$db->RecordCount($query_nums0);

$pageno=ceil($numrows0/$pagesize);//取出页码数 $query_newsList = "exec sp_fastexec $start,$pagesize,". split_sql($query_newsList);
// echo $query_newsList;
$rs_newsList_result=tep_db_query($query_newsList);

?>                 </td>
          <td width="737" height="18" align="right" bgcolor="#0058A8" class="white"><div align="right">
              <? 
/************分页************/
$up=$page-1;
$dn=$page+1;
echo "共".$pageno."页&nbsp;当前第".$page."页&nbsp;";
if($page>1)
{ echo "<a href='".tep_href_link
('cxly_list.php','page='.$up.'&category='.$category1.'&lysj='.$lysj.'&jzsj='.$jzsj.'&hid_seach=1')."'><font size=2>上一页</font></a>&nbsp;";

}
else echo "<font size=2>上一页</font>&nbsp;";
if($page>=$pageno)
echo "<font size=2>下一页</font>";
else echo "<a href='".tep_href_link
('cxly_list.php','page='.$dn.'&category='.$category1.'&lysj='.$lysj.'&jzsj='.$jzsj.'&hid_seach=1')."'><font size=2>下一页</font></a>";
/************分页************/


?>
&gt;&gt;</div></td>
          <td height="18" bgcolor="#000066" width="2"></td>
        </tr>
        <tr>
          <td height="1" bgcolor="#000066" colspan="4"></td>
        </tr>
      </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td height="1"></td>
          </tr>
        </table>
        <table width="100%" border="1" cellspacing="0" cellpadding="0" class="wz" bgcolor="#EEEEEE" bordercolor="#0058A8">
          <tr>
 <td align="left" width="18%" bgcolor="#999999" bordercolor="#FFFFFF"><div align="center" class="style2">所属对象</div></td>
<td align="left" width="16%" bgcolor="#999999" bordercolor="#FFFFFF"><div align="center" class="style2">所属促销类别</div></td>
<td align="left" width="19%" bgcolor="#999999" bordercolor="#FFFFFF"><div align="center" class="style2">用户名</div></td>
<td align="left" width="21%" bgcolor="#999999" bordercolor="#FFFFFF"><div align="center" class="style2">留言日期</div></td>      
 <td width="26%" bgcolor="#999999" bordercolor="#FFFFFF"><div align="center"><font color="#FFFFFF">操 作</font></div></td>
          </tr>
        </table>
        <?
while($rs_newsList=tep_db_fetch_array($rs_newsList_result))
{ $yhm=$rs_newsList['yhm'];
$lybs=$rs_newsList['lybs'];
        $ly_smc=$rs_newsList['smc'];
$ly_content=$rs_newsList['ly'];
if($rs_newsList['ssfl'] =="1")  $gg_category ="代购";
else if ($rs_newsList['ssfl'] =="2")  $gg_category ="团购";
else if ($rs_newsList['ssfl'] =="3")  $gg_category ="优惠券";
$yhbs=$rs_newsList['yhbs'];

//echo $yhm;
$lyrq=$rs_newsList['lyrq'];

?>        <table width="100%" border="1" cellspacing="0" cellpadding="0" height="20" class="wz" bgcolor="#EEEEEE" bordercolor="#CCCCCC">
          <tr>
<td width="18%" bgcolor="#FFFFFF"><div align="center"><?=$ly_smc?></div></td>
<td width="16%" bgcolor="#FFFFFF"><div align="center"><?=$gg_category?></div></td>
<td width="19%" bgcolor="#FFFFFF"><div align="center"><?=$yhm?></div></td>
<td width="21%" bgcolor="#FFFFFF"><div align="center"><?=$lyrq?></div></td>
<td width="12%" bgcolor="#FFFFFF"><div align="center">
<? if($lybs!=''){ ?>
<a href="<?php echo tep_href_link('cxly_modify.php','ly_id='.$lybs);?>">修 改</a>
<? } else if ($lybs=='')
echo "修改";
 ?>
</div></td>
<td width="14%" bgcolor="#FFFFFF"><div align="center">
<? if($lybs!=''){ ?>
<a href="cxly_list.php?ly_id=<?php echo $lybs;?> &del=1" onClick="javascript:if(confirm('确定删除本条信息吗?')) return true;else return false;">删 除</a>
<? } else if ($lybs=='')
echo "删除";
 ?>
</div></td>  
 
  </tr>
        </table>
        <?
  }
  ?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td height="1" colspan="4"></td>
          </tr>
          <tr>
            <td height="1" bgcolor="#FFFFFF" colspan="4"></td>
          </tr>
          <tr>
            <td height="18" bgcolor="#FFFFFF" width="1"></td>
            <td width="136" height="18" bgcolor="#0058A8" class="white" align="right">&nbsp;</td>
            <td height="18" bgcolor="#0058A8" width="849" class="white" valign="middle"><div align="right" >
              <? 
/************分页************/
$up=$page-1;
$dn=$page+1;
echo "共".$pageno."页&nbsp;当前第".$page."页&nbsp;";
if($page>1)
{ echo "<a href='".tep_href_link
('cxly_list.php','page='.$up.'&category='.$category1.'&lysj='.$lysj.'&jzsj='.$jzsj.'&hid_seach=1')."'><font size=2>上一页</font></a>&nbsp;";

}
else echo "<font size=2>上一页</font>&nbsp;";
if($page>=$pageno)
echo "<font size=2>下一页</font>";
else echo "<a href='".tep_href_link
('cxly_list.php','page='.$dn.'&category='.$category1.'&lysj='.$lysj.'&jzsj='.$jzsj.'&hid_seach=1')."'><font size=2>下一页</font></a>";
/************分页************/


?>怎么会出现前一页的最后一条记录怎么在后一页显示在第一条呢?请指教....

解决方案 »

  1.   

    太长了,没仔细看,
    查一下,是不是limit 计算起始数时出了问题,?
      

  2.   

    我刚开始学PHP,下面是我改的一个mysql操作类,希望对大家有帮助<?php
    //-------------------------------------------------------------------
    //Author: unknown
    //Edit: CSDN - fify2046
    //Date: 2008-3-20
    //Desc: 带分页功能的mysql操作类,可用于更新、查询、查询单个数值、查询分页
    //PHP Version:  5.0+
    //
    // 版权没有,转载随意
    //-------------------------------------------------------------------
    class db_mysql
    {
    public $db_host;
    public  $db_user;
    public  $db_password;
    public  $db_database;
    public  $result;
    public  $conn;
    public  $sql;
    public  $row;
    public  $err_msg;
    public  $rowcount; //构造函数
    public function __construct($db_host,$db_user,$db_password,$db_database)
    {
    $this->db_host = $db_host;
    $this->db_user = $db_user;
    $this->db_password = $db_password;
    $this->db_database = $db_database;
    } //连接数据库
    public function Open()
    {
    $conn = mysql_connect($this->db_host,$this->db_user,$this->db_password);
    if(!$conn)
    {
    $this->msg_error("无法连接数据库服务器");
    }
    else
    {
    $this->conn = $conn;
    }
    if(!mysql_select_db($this->db_database,$this->conn))
    {
    $this->msg_error("无法选择数据库");
    }
    } //更新数据库
    public function ExecuteNonQuery($sql)
    {
    $this->sql = $sql;
    if(!mysql_query($this->sql,$this->conn))
    {
    $this->msg_error(("更新数据出错!"));
    }
    else
    {
    $this->rowcount =  mysql_affected_rows();
    }
    } //查询数据并返回result
    public function ExecuteReader($sql)
    {
    $this->sql = $sql;
    $result = mysql_query($this->sql,$this->conn); if(!$result)
    {
    $this->msg_error("查询数据出错!");
    }
    else
    {
    $this->result = $result;
    $this->rowcount =  mysql_num_rows($result);
    }
    } //分页查询数据并返回result类型
    //参数idcol是指自增列的名称,可自动生成高效分页sql,为空则使用简单分页
    //countelse表示是否计算总记录数,如果是false,则之后的参数没必要给了
    //countsql是计算总记录数的sql,如果为空则自动生成一个
    //后面两个是按引用传递的参数,使用的时候请注意
    public function ExecuteReaderByPage($sql, $pagesize, $curpage, $idcol='', $countelse = false, $countsql = '', &$pagecount = 0, &$recordcount = 0)
    {
    if($countelse)
    {
    if($countsql != '')
    {
    $recordcount = $this->ExecuteScalar($countsql);
    $pagecount = ceil($recordcount / $pagesize);
    }
    else
    {
    $countsql = $this->InitCountSql($sql);
    $recordcount = $this->ExecuteScalar($countsql);
    $pagecount = ceil($recordcount / $pagesize);
    }
    } if($idcol == '')
    {
    $iMin = 0;
    if($curpage > 1){ $iMin = ($curpage - 1) * $pagesize; } $this->sql = $sql . " LIMIT {$iMin},{$pagesize}";
    }
    else
    {
    $this->sql = $this->InitPagerSql($sql, $pagesize, $curpage, $idcol);
    } $result = mysql_query($this->sql, $this->conn); if(!$result)
    {
    $this->msg_error("查询数据出错!");
    }
    else
    {
    $this->result = $result;
    $this->rowcount =  mysql_num_rows($result);
    }
    } //取得单个数值
    public function ExecuteScalar($sql)
    {
    $this->sql = $sql;
    $result = mysql_query($this->sql, $this->conn); if(!$result)
    {
    $this->msg_error("查询数据出错!");
    }
    else
    {
    $this->result = $result;
    $this->rowcount =  mysql_num_rows($result);
    }
    $ary = mysql_fetch_array($result);
    return $ary[0];
    } //取得记录集
    public function Read()
    {
    $this->row = mysql_fetch_array($this->result);
    return $this->row;
    } //根据自增列生成更高效的分页sql语句
    protected function InitPagerSql($sql, $pagesize, $curpage, $idcol = '')
    {
    if($idcol != '')
    {
    $iMin = 0;
    if($curpage > 1){ $iMin = ($curpage - 1) * $pagesize; } $sql = strtolower($sql);
    $iw = strpos($sql, ' where') + strlen(' where') + 1;
    $fsql = substr($sql, 0, $iw);
    $lsql = substr($sql, $iw);
    $flag = strpos($sql,' desc')? '<=':'>=';
    $if = strpos($sql, ' from') + strlen(' from') + 1;
    $iw1 = strpos($sql, ' where');
    $tbname = substr($sql, $if, $iw1-$if);
    $sql = "{$fsql} {$idcol} {$flag}(SELECT {$idcol} FROM {$tbname} WHERE {$lsql} LIMIT {$iMin},1) AND {$lsql} LIMIT {$pagesize}";
    }
    return $sql;
    }
    //生成Count(*)的SQL
    protected function InitCountSql($sql)
    {
    if($sql != '')
    {
    $sql = strtolower($sql);
    $if = strpos($sql, ' from');
    $lsql = substr($sql, $if);
    $io = strpos($lsql, ' order')? strpos($lsql, ' order'):strlen($lsql);
    $lsql = substr($lsql, 0, $io);
    $sql = "SELECT COUNT(*) {$lsql}";
    }
    return $sql;
    } //释放结果集
    protected function Free()
    {
    mysql_free_result($this->result);
    }
    //关闭连接
    public function Close()
    {
    if($this->result) { $this->free(); }
    mysql_close($this->conn);
    }
    // 根据执行结果取得影响行数
    public function GetRowCount()
    {
    return $this->rowcount;
    } //指向确定的一条数据记录
    public function DataSeek($result,$i)
    {
    mysql_data_seek($result,$i);
    return $this->result;
    } //通用数据库错误处理
    protected function msg_error($message, $isdie = true)
    {
    $this->err_msg = $message;
    if($isdie) die("Error: ".$message. mysql_error() );
    }
    }
    ?>
      

  3.   

    class dispersion//分页类
    {
    var $page;
    var $pagecount;
    var $pagesize;
    var $num;
    var $scriptname;
    var $filename;
    var $startresult;
    function dispersion_page($sql,$size,$count)//返回当前页的SQL语句
    {
    //echo "2<br>";
    $this->pagesize = $size;
    $this->num = $count;
    if(!isset($_GET["p"]))
    {
    $this->page=0;
    }
    else
    {
    $this->page = $_GET["p"];
    }
    if(($this->num % $this->pagesize) == 0) //得到总页数
    {
    //echo "3<br>";
    $this->pagecount = intval($this->num / $this->pagesize);
    }
    else
    {
    //echo "4<br>";
    $this->pagecount = intval($this->num / $this->pagesize) + 1;
    }
    if(isset($this->page))//设置当前页
    {
    //echo "5<br>";
    if($this->page <= 0)
    {
    //echo "6<br>";
    $this->page = 1;
    }
    else
    {
    //echo "7<br>";
    $this->page = $_GET["p"];
    }
    if($this->page > $this->pagecount)
    {
    //echo "8<br>";
    $this->page = $this->pagecount;
    }
    }
    else
    {
    //echo "9<br>";
    $this->page = 1;
    }



    $this->startresult = ($this->page - 1) * $this->pagesize;
    $sql = $sql." limit ".$this->startresult.",".$this->pagesize;
    //echo $sql."<br>";
    return $sql; //得到SQL语句
    }
    function pageinfo($color)//页数信息
    {

    echo "<style type='text/css'>
    <!--
    .dispersion_color {color: ".$color."}
    -->
    </style>";
    //echo "10<br>";
    echo "当前显示第<span class='dispersion_color'>".$this->page."</span>页 ";
    echo "每页<span class='dispersion_color'>".$this->pagesize."</span>条 ";
    echo "共有<span class='dispersion_color'>".$this->num."</span>条记录 ";
    echo "共有<span class='dispersion_color'>".$this->pagecount."</span>页<br>";
    }


    function pagebutton($getinfo)
    {
    //echo "11<br>";
    if(($this->pagecount != 0) && ($this->pagecount != 1))//防止数据库为空与只有一页
    {
    //echo "12<br>";
    $this->scriptname = split("[/]",$_SERVER["SCRIPT_NAME"]);
    $this->filename = end($this->scriptname);//得到本页名称
    if ($this->page != 1)
    {
    //echo "13<br>";
    echo "<a href='".$this->filename."?p=1".$getinfo."'>第一页</a> ";
    }
    if ($this->page > 1)
    {
    //echo "14<br>";
    echo "<a href='".$this->filename."?p=".($this->page - 1).$getinfo."'>上一页</a> ";
    }
    if ($this->page < $this->pagecount)
    {
    //echo "15<br>";
    echo "<a href='".$this->filename."?p=".($this->page + 1).$getinfo."'>下一页</a> ";
    }
    if ($this->page != $this->pagecount)
    {
    //echo "16<br>";
    echo "<a href='".$this->filename."?p=".$this->pagecount.$getinfo."'>最后一页</a>";
    }
    }
    }
    //3个function   用一下就OK了
      

  4.   

    我把分页类整在php的数据库类里面好多年了,也觉得应该改改了.借这个机会一起聊聊.<?
    /**
    * 数据库类.

    * 封装常见的数据库操作,包括分页处理.

    * @author  徐兴
    * @package lib
    * @version v1.0
    * @copyright juwangTech.
    *
    */
    class db {
    /**
     * 可以选择mysql oracle sql
     * @access  public
     * @var   数据库类型 
     */
    public $dbtype='mysql';   

    /**
     * 默认的数据库连接所用的用户名.
     * @access  public
     * @var   数据库用户名  
     */
    public $user='';  

    /**
     * 默认的数据库连接所用的用户密码
     * @access  public
     * @var   数据库密码 
     */
    public $pass='';           
    /**
     * 数据库主机地址,本机默认写localhost
     * @access  public
     * @var   数据库主机地址 
     */
    public $host='';    /**
     * 指定的不当前操作的数据库
     * @access  public
     * @var   数据库,指定的库
     */
    public $database='';   /**
     * 数据库的连接句柄
     * @access  public
     * @var   句柄
     */
    public $handle;        

    /**
     * 记录集
     * @access  public
     * @var   记录集
     */
    public $rs = array();      

    /**
     * 最后一次记录集
     * @access  public
     * @var   最后一次记录集
     */
    public $last_rs = '';     

    /**
     * 分页记录中一页数据的行数
     * @access  public
     * @var   分页记录中一页数据的行数
     */

    public $rows_num=0;        //记录行数
    public $page=0;            //页
    public $pages_num=0;       //页数
    public $rows_per_page=0;   //每页记录行数
    public $rows_offset=0;     //行偏移,使用较少
    public $params='';          //参数
    public $show_page_num=0;   //页式2时示页(为)
    public $func_ary = array(  
    'farray'       => 'mysql_fetch_array',
    'fnum'         => 'mysql_fetch_row',
    'ffield'       => 'mysql_fetch_assoc',
    'fobject'      => 'mysql_fetch_object',
    );
    /**
     * 指定数据库类型,是mysql 还是sql,还是orecle.
     * @param 数据库的类型 $type
     * @return bool
     */
    function __construct( $type='mysql' ) {
    if( $type!='' ) $this->dbtype = $type;
    if( !$this->func_ary[$this->dbtype] ) {
    return false;
    }else {
    return true;
    }
    }
      /**
       * *创建一个数据库的连接.
       *
       * @param string $host -主机名称
       * @param string $user -数据库用户名
       * @param 数据库用户密码 $pass
       * @return 数据库句柄.handle 
       */
    function conn( $host = '192.168.100.137' , $user = 'XX' , $pass = 'XX' ) {
    if( gettype( $host ) == 'resource' ) {
    $this->handle = $host;
    }else {
    if( $host != '' ) $this->host = $host;
    if( $user != '')  $this->user = $user;
    if( $pass != '')  $this->pass = $pass;
    $this->handle = mysql_connect( $this->host , $this->user , $this->pass , false , MYSQL_CLIENT_COMPRESS ) or die( "系统忙,请稍厚" );
    $this->query( "SET NAMES utf8") or die( "set names utf-8 失败" );
    return $this->handle;
    }
    } /**
     * *关闭数据库连接.
     *
     */
    function close() {
    @mysql_close($this->handle);
    } /**
     * *指定所选的数据库.
     *
     * @param 指定的当前操作的数据库名. $database
     */
    function setdb( $database = 'pm' ) {
    if( $database != '' ) $this->database = $database;
    @mysql_select_db( $this->database , $this->handle );
    } /**
    * 执行一个sql语句.
    * @param 查询语句,支持单个sql和数组模式.。 $sql
    * @return 
        */              
    function query( $sql ) {
    if( is_array( $sql ) ) {

    for($i=0; $i<sizeof($sql); $i++) {
    $tmp = @mysql_query($sql[$i],$this->handle);
    }
    return $tmp;
    }else {
    return @mysql_query($sql,$this->handle);
    }
    } /**
    * 取出最新插入数据库的id号.
    * @return  int 
    */  
    function insid() {
    return @mysql_insert_id($this->handle);
    } /**
    * 获取影响的行数.
    */  
    function affrow() {
    return @mysql_affected_rows($this->handle);
    } /*  */
    function err() {
    return array(@mysql_errno(), @mysql_error($this->handle));
    } /* 已记录集方式得到记录本 */
    function rs( $sql = '' , $rs_name = '' ) {
    if( $rs_name == '' && $this->last_rs == '') {
    $rs_name='rs';
    }elseif( $rs_name == '' ) {
    $rs_name = $this->last_rs;
    }
    $sql_tmp = is_array( $sql )? $sql [ sizeof( $sql ) ] : $sql;
    if( $sql_tmp != '' && $this->result[ $rs_name ][ 0 ] != $sql ){
    $tmp = $this->query( $sql );
    $this->result[ $rs_name ] = array( $sql_tmp,$tmp );
    $this->last_rs = $rs_name;
    }
    return $this->result[ $rs_name ][1];
    } /* 以数组方式取得 */
    function rn( $sql='' , $type = 'num' , $rs_name = '',$num = 1) {
    if( !$type ) $type = 'num';
    if( !in_array( $type , array( 'num' , 'field' , 'array' , 'object' ))) return false;
          if( $num == 1 ) {
    return @$this->func_ary[ 'f'. $type ]( $this->rs( $sql , $rs_name));
    }elseif( $num == 'all' ) {
    while( $tmp[] = @$this->func_ary[ 'f'.$type ]( $this->rs( $sql , $rs_name ))) {
    }
    }elseif( is_int( $num )) {
    for( $i = 0 ;  $i < $num ; $i++ ) {
    $tmp1 = @$this->func_ary[ 'f'.$type ]( $this->rs( $sql , $rs_name ) );
    if( $tmp1 === false ) {
    break;
    }else {
    $tmp[] = $tmp1;
    }
    }
    }else {
    return false;
    }
    return $tmp;
    } /**
     *  得到单值 
     */
    function val( $sql ) {
    if( DEBUG == "1" ){echo $sql."<hr/>";}

    $tmp = mysql_fetch_row($this->query($sql));
    if( is_null($tmp)) {
    echo "没有你要取得值";
    }
    return $tmp[0];
    }


    /**
     * 通过表中的一个字段的值来取得另个字段,或者是一组数据的方法.
     * @param  值的编号. $id
     * @param  需要取得的数据的字段名. $attrName
     * */
    function getValue($id,$attrName,$table,$condKey)
    {
    $table = $table;
    $cond = "where $condKey = '$id'";
    $sql = "select $attrName from $table $cond";

        if(DEBUG == "1")
    {
    echo "getValue".$sql."<hr/>";
    }
     
    $value = $this->val($sql);
    if(DEBUG == "1")
    {
    echo "你所求的值为 $value    |";
    }
     return $value;
    }



    /**
     *  得到行数 
     */
    function num($sql='',$rs_name='rs') {
    return @mysql_num_rows($this->rs($sql,$rs_name));
    }
    /**
     *  清空记录集 
     */
    function clean($rs_name) {
    if(is_array($rs_name)) {
    foreach($rs_name as $val) {
    @mysql_free_result($this->result[$rs_name][1]);
    unset($this->result[$val]);
    }
    }else {
    @mysql_free_result($this->result[$rs_name][1]);
    unset($this->result[$rs_name]);
    }
    }
    /**
     *  重设记录集 
     */
    function reset ($rs_name) {
    if(is_array($rs_name)) {
    foreach($rs_name as $val) {
    @mysql_data_seek($this->result[$val][1],0);
    }
    }else {
    @mysql_data_seek($this->result[$rs_name][1],0);
    }
    }
      

  5.   

    续... /**
     *  指定分页 
     */
    function pnum($page,$rows_num,$rows_per_page=20,$offset=0) {
    if($rows_num)      $this->rows_num      = $rows_num;
    if($rows_per_page) $this->rows_per_page = $rows_per_page;
    if($offset)        $this->offset        = $offset;
    if(!$page)         $page =1;
    $this->page = $page;
    $this->pages_num = ceil(($this->rows_num-$this->offset)/$this->rows_per_page);
    Return $this->pages_num;
    }
    /* 进行分页处理 */
    function page($sql,$rs_name='') {
    switch($this->dbtype) {
    case 'mysql':
    $sql = $sql." limit ".(($this->page-1)*$this->rows_per_page+$this->offset).", ".$this->rows_per_page;


    return $this->rs($sql,$rs_name);
    break;
    }
    }
    /**
     * * 输出分页条.
     *
     * @param 分页的格式类型 $style
     * @param 显示多少个分页标签. $show_page_num
     */
    function nav(  $style='nav1',  $show_page_num=15 ) {
    switch( $style ) {
    /* 分页1:  页 | 页 | 页 | 末页 */
    case 'nav1':
    if ( $this->page > 1 ) {
    $nav .= '<a href="?page=1&'. $this->params .'" class="page_linked">页</a> | ';
    $nav .= '<a href="?page='. ($this->page-1) .'&'. $this->params .'"  class="page_linked">页</a> | ';
    }else {
    $nav .= '<span class="page_unlink">页</span> | ';
    $nav .= '<span class="page_unlink">页</span> | ';
    }
    if ($this->page < $this->pages_num ) {
    $nav .= '<a href="?page='.( $this->page+1 ).'&'. $this->params .'" class="page_linked">页</a> | ';
    $nav .= '<a href="?page='. $this->pages_num .'&'. $this->params .'" class="page_linked">末页</a>';
    }else {
    $nav .= '<span class="page_unlink">页</span> | ';
    $nav .= '<span class="page_unlink">末页</span>';
    }
    break;
    /* 分页模式2:   1 2 3 4 5 6 7 8 9 页*/
    case 'nav2':
    for( $i=1 ; $i <= $this->pages_num; $i++ ) {
    if( $i == $this->page ) {
    $nav .= " <font style='font-size:12pt' face='Verdana'><b> $i </b></font> ";
    }else {
    $nav .= " <a href=?page=$i&". $this->params ."><font style='font-size:9pt;' face='Verdana'>$i</font></a> ";
    }
    }
    $nav = " $nav 页";
    break;
    case 'nav3':
    echo "
    <style>
    .page, .page_select
    {
    width:25px;
    text-decoration: none;
    text-align: center;
    border: 1px solid #092FB3;
    font-size:9pt;
    float:left;
    line-height:25px;
    margin-right:2px;
    }
    .page{
    color:#092FB3;
    background-color: #EEF8FF;
    display:block;
    }
    .page_select
    {
    color:#EEF8FF;
    background-color: #092FB3;
    font-weight: bolder;
    }
    .a_nav
    {
    color:#092FB3;
    text-decoration: none;
    text-align: center;
    font-size:9pt;
    line-height:25px;
    float:left;
    }
    </style>
    ";
    if($show_page_num) $this->show_page_num = $show_page_num;
    $page          = $this->page;
    $show_page_num = $this->show_page_num;
    $pages_num     = $this->pages_num;
    $param         = $this->params;
    $mid = ceil(($show_page_num+1)/2);
    $nav = '';
    if($page<=$mid ) {
    $begin = 1;
    }else if($page > $pages_num-$mid) {
    $begin = $pages_num-$show_page_num+1;
    }else {
    $begin = $page-$mid+1;
    }

    /**
     * patch for param; 保留原有的查询条件.
     * */
    $param = $_SERVER["QUERY_STRING"];
    $pattern = "/&page=(\d)/i";
    $replacement = "";
    $param =  preg_replace($pattern, $replacement, $param);

    if($begin<0) $begin = 1;
    if($begin!=1) $nav .= " <a href='?$param&page=1' title='1页' class ='a_nav'><< 首页</a>  ";
    if($page>1)   $nav .= " <a href='?$param&page=".($page-1)."' title='".($page-1)."页' class ='a_nav'><<上一页</a> ";
    $end = ($begin+$show_page_num>$pages_num)?$pages_num+1:$begin+$show_page_num;
    for($i=$begin; $i<$end; $i++) {
    $nav .=($page!=$i)?" <a href='?$param&page=$i' class = 'page'  title='{$i}页'>$i</a> ":" <span  class = 'page_select'>$i</span> ";
    }
    if($page<$pages_num)   $nav .= " <a href='?$param&page=".($page+1)."' title='".($page+1)."页' class ='a_nav'>下一页 >></a> ";
    if($end!=$pages_num+1) $nav .= "  <a href='?$param&page=$pages_num' title='{$pages_num}页' class ='a_nav'>尾页 >></a> ";
    break;

    /* 第四类分页 */
    case 'nav4':
    if($show_page_num) $this->show_page_num = $show_page_num;
    $page          = $this->page;
    $show_page_num = $this->show_page_num;
    $pages_num     = $this->pages_num;
    $param         = $this->params;
    if (!$pages_num) $pages_num =1;
    $nav = "<a href='?$param' title='1页'><font face=webdings>9</font></a> ";

    if ($page>1) {
    $nav .="<a href='?$param&page=".($page-1)."' title='".($page-1)."页'><font face=webdings>7</font></a> ";
    }else {
    $nav .= "<font face=webdings>7</font> ";
    }
    if ($page<=2||$pages_num<$show_page_num) {
    $begin=1;
    } elseif ($page>$pages_num-$show_page_num+2) {
    $begin = $pages_num-$show_page_num+1;
    }else {
    $begin = $page-2;
    }
    if ($pages_num<$show_page_num) {
    $end =$pages_num;
    }else {
    $end = $begin+$show_page_num-1;
    }

    for ($i=$begin;$i<=$end;$i++) {
    $nav .=($page!=$i)?"<a href='?$param&page=$i' title='{$i}页' class=nav> $i </a> ":"<font color='#000000'><b> <U>$i</U> </b></font> ";
    }

    if ($page<$pages_num) {
    $nav .="<a href='?$param&page=".($page+1)."' title='".($page+1)."页'><font face=webdings>8</font></a> ";
    }else {
    $nav .= "<font face=webdings>8</font> ";
    }
     $nav .="<a href='?page=$pages_num&$param' title='尾页'><font face=webdings>:</font></a>  <b><font color='#74A2DE'>".$pages_num."</font>页</b>";
    break;
    /*直转 */
    case 'listjump':
    $nav = '
     <select onchange="location.href=\'?'.$this->params.'&page=\'+this.value;">
    <script language="JavaScript">
    <!--
    for(i=1; i<='.$this->pages_num.'; i++) {
    document.write("<option value="+i+(i=='.$this->page.'?" selected":"")+">"+i+"</option>");
    }
    //-->
    </script>
    </select> 页';
    break;
    case 'inputjump':
    return "<script language='javascript'>function pagejump(){if (document.all.pagejmp.value == ''|| document.all.pagejmp.value < 0 ) {document.all.pagejmp.focus();alert('转页搿?;return false;}else{this.location.href = '?page='+document.all.pagejmp.value+'&".$this->params."'; target = '_self';}}</script>  转 <input name=pagejmp size=2 onkeydown='if(window.event.keyCode==13) pagejump();'> 页 <img src=".gd('user')."images/go1.gif align=absmiddle onclick='pagejump();' style='cursor:hand;'>";
    break;
    case 'imagejump':
    return "<script language='javascript'>function pagejump(){if (document.all.pagejmp.value == ''|| document.all.pagejmp.value < 0 ) {document.all.pagejmp.focus();alert('转页搿?;return false;}else{this.location.href = '?page='+document.all.pagejmp.value+'&".$this->params."'; target = '_self';}}</script>  转 <input name=pagejmp size=4 onkeydown='if(window.event.keyCode==13) pagejump();' style='border:1px solid #424242; height:16px;'> 页 <img src=".gd('magzine')."images/go.gif align=absmiddle onclick='pagejump();' style='cursor:hand;' width=25 height=17>";
    break;
    default:
    $nav = '';
    }
    return $nav;
    }
    }
    /**
     *   数据库初始化问题。 
     */
    function db_init() {
    global $db;
    $db = new db();
    $db->conn();
    $db->setdb("pm");
    }
      

  6.   

    通常我用pnum 来设置一下.
    查询时用db->page方法.
    然后就直接输入db->nav()来render 导航条.写的比较死,但由于长期已来分页变化不是特别的大.所以就一直用下来了,感觉也比较顺手.但从代码质量的规划来看,应该分开.最好还能很方便的调用各种各样的模式,特别是ajax之类的分页.最近还做了一个滚动条的.
    感觉应该好好的分分了,希望大家多交流,提出好的想法的代码来.
      

  7.   

    我也来贴一下我的分页类,我一直都在用,几个月没出新版本了,希望大家给点意见,出个新版本。http://www.twycn.com/bbs/viewthread.php?tid=93&page=1&extra=page%3D1