<?
require('../inc/conn.php');
     #############取得记录总数##############
  $query3="select count(*) as orders from  $tb_news_property where type='$type'"; 
      $result3=mysql_query($query3); 
      if($result3) 
          { 
               $data=mysql_fetch_array($result3);
               $orders=$data["orders"];
       }
       else
        {
        echo "有错误发生,请检查数据库!";
         exit;
           }
#####################取得记录总数完成##################if (isset($jumpto)) 

  if ($jumpto<=$pages) 
     {$offset=$jumpto;} 
     else      
{$offset=$last_offset;} 
 }
if (empty($offset))
 {
    $offset=0;  
          }   $sqltype="select title,id,DT from $tb_news_property where type='$type' LIMIT $offset,10";
   $querytype=mysql_query($sqltype);?>
接下来是显示分页的代码了:<form method=post action=<? $PHP_SELF;?>>  
  <table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
    <tr>
                
                                <td height="20" bgcolor="#FFFFFF"> 
                                  <div align="right">目前共<font color="#ff0000"> 
                              <?=$orders ?>
                              </font> <font color="#000000">条记录,</font>   
                              <?
  if($orders<10){echo"首页";}
  else{
  ?>
                              <a href="<?=$PHP_SELF;?>?offset=0&type=<?=$type?>">首页</a> 
                              <? }
if($offset) //如果偏移量是0,不显示前一页的链接  
{  
$preoffset=$offset-10;  
print "<a href=$PHP_SELF?offset=$preoffset&type=$type>前一页</a>"; 
}  
//计算总共需要的页数  
$pages=ceil($orders/10); //$pages变量现在包含所需的页数  //检查是否是最后一页  
//if ($pages!=0 && ($newoffset/10)!=$pages)  
$nextoffset=$offset+10; 
if (($pages!=0) && ($nextoffset<$orders))    
{  
  print "<a href=$PHP_SELF?offset=$nextoffset&type=$type>下一页</a>"; 
   
}    $last_offset=($pages-1)*10; 
  $this_page_no=ceil($offset/10)+1; 
?>
                              <?
 if($Orders<10){echo"尾页";}
 else{
 ?>
                              <a href="<?=$PHP_SELF;?>?offset=<?=$last_offset;?>&type=<?=$type?>">尾页</a> 
                              <?}?>
                              页次:<font class="red"> 
                              <?=$this_page_no;?>
                              /</font> 
                              <?=$pages;?>
                              页 到第: 
                              <input<?php if($orders<10){?> disabled<?php }?> type="text" name="jumpto" size="2" maxlength="4">
                页 
                <input<?php if($orders<10){?> disabled<?php }?> type="submit" name="Submit" value="go">
              </div></td>
              </tr></table> 
</form>

解决方案 »

  1.   

    <?php
    /**
     * 一个用于Mysql数据库的分页类
     *
     * @author      Avenger <[email protected]>
     * @version     1.0
     * @lastupdate  2003-04-08 11:11:33
     *
     *
     * 使用实例:
     * $p = new show_page; //建立新对像
     * $p->file="ttt.php"; //设置文件名,默认为当前页
     * $p->pvar="pagecount"; //设置页面传递的参数,默认为p
     * $p->setvar(array("a" => '1', "b" => '2')); //设置要传递的参数,要注意的是此函数必须要在 set 前使用,否则变量传不过去
     * $p->set(20,2000,1); //设置相关参数,共三个,分别为'页面大小'、'总记录数'、'当前页(如果为空则自动读取GET变量)'
     * $p->output(0); //输出,为0时直接输出,否则返回一个字符串
     * echo $p->limit(); //输出Limit子句。在sql语句中用法为 "SELECT * FROM TABLE LIMIT {$p->limit()}";
     *
     */
    class show_page {    /**
         * 页面输出结果
         *
         * @var string
         */
    var $output;    /**
         * 使用该类的文件,默认为 PHP_SELF
         *
         * @var string
         */
    var $file;    /**
         * 页数传递变量,默认为 'p'
         *
         * @var string
         */
    var $pvar = "p";    /**
         * 页面大小
         *
         * @var integer
         */
    var $psize;    /**
         * 当前页面
         *
         * @var ingeger
         */
    var $curr;    /**
         * 要传递的变量数组
         *
         * @var array
         */
    var $varstr;    /**
         * 总页数
         *
         * @var integer
         */
        var $tpage;    /**
         * 分页设置
         *
         * @access public
         * @param int $pagesize 页面大小
         * @param int $total    总记录数
         * @param int $current  当前页数,默认会自动读取
         * @return void
         */
        function set($pagesize=20,$total,$current=false) {
    global $HTTP_SERVER_VARS,$HTTP_GET_VARS; $this->tpage = ceil($total/$pagesize);
    if (!$current) {$current = $HTTP_GET_VARS[$this->pvar];}
    if ($current>$this->tpage) {$current = $this->tpage;}
    if ($current<1) {$current = 1;} $this->curr  = $current;
    $this->psize = $pagesize; if (!$this->file) {$this->file = $HTTP_SERVER_VARS['PHP_SELF'];} if ($this->tpage > 1) {
                
    if ($current>10) {
    $this->output.='<a href='.$this->file.'?'.$this->pvar.'='.($current-10).($this->varstr).' title="前十页">&lt;&lt;&lt;</a>&nbsp;';
    }
                if ($current>1) {
    $this->output.='<a href='.$this->file.'?'.$this->pvar.'='.($current-1).($this->varstr).' title="前一页">&lt;&lt;</a>&nbsp;';
    }            $start = floor($current/10)*10;
                $end = $start+9;            if ($start<1) {$start=1;}
                if ($end>$this->tpage) {$end=$this->tpage;}            for ($i=$start; $i<=$end; $i++) {
                    if ($current==$i) {
                        $this->output.='<font color="red">'.$i.'</font>&nbsp;';    //输出当前页数
                    } else {
                        $this->output.='<a href="'.$this->file.'?'.$this->pvar.'='.$i.$this->varstr.'">['.$i.']</a>&nbsp;';    //输出页数
                    }
                }            if ($current<$this->tpage) {
    $this->output.='<a href='.$this->file.'?'.$this->pvar.'='.($current+1).($this->varstr).' title="下一页">&gt;&gt;</a>&nbsp;';
    }
                if ($this->tpage>10 && ($this->tpage-$current)>=10 ) {
    $this->output.='<a href='.$this->file.'?'.$this->pvar.'='.($current+10).($this->varstr).' title="下十页">&gt;&gt;&gt;</a>';
    }
    }
    }    /**
         * 要传递的变量设置
         *
         * @access public
         * @param array $data   要传递的变量,用数组来表示,参见上面的例子
         * @return void
         */
    function setvar($data) {
    foreach ($data as $k=>$v) {
    $this->varstr.='&amp;'.$k.'='.urlencode($v);
    }
    }    /**
         * 分页结果输出
         *
         * @access public
         * @param bool $return 为真时返回一个字符串,否则直接输出,默认直接输出
         * @return string
         */
    function output($return = false) {
    if ($return) {
    return $this->output;
    } else {
    echo $this->output;
    }
    }    /**
         * 生成Limit语句
         *
         * @access public
         * @return string
         */
        function limit() {
    return (($this->curr-1)*$this->psize).','.$this->psize;
    }} //End Class
    ?>
      

  2.   

    http://expert.csdn.net/Expert/topic/2756/2756615.xml?temp=.8755457
      

  3.   

    <?php
        //通用变量,请进行设置
    $host = "localhost";             //主机名,一般为localhost
    $user = "";                      //Mysql用户名:一般为root或空格
    $password = "";                  //Mysql密码:一般为root或空格
    $databasename = "china";       //数据库名
    $tablename= "iptable";           //留言本数据对应的表的名称
    $pagesize = 300; //每页数量
    //-------------------------------------------------------------------
    //连接数据库
    mysql_connect("$host","$user","$password") or die("<font color=red>不能连接到数据库服务器,请与斑竹联系,谢谢!</font>");
    mysql_select_db("$databasename");
    if($page=="")
    {
    $page=0;
    }
    ?>
    <center><font size=2 color=#aaaaaa>网站访问<a target='_self' href='ipshow.php'><font color=#aaaaaa>统计</font></a>:记录总数为
    <?php
    //-------------------------------------------------------------------
    //计算有多少个记录要显示
    $query00 = "select * from $tablename";
    $result00 = mysql_query($query00);
    $total= mysql_numrows($result00);
    $totalpage=(int)($total/$pagesize)+1;
    if(!($total%$pagesize))$totalpage--;
    echo $total.",共".$totalpage."页";
    ?></font></center><center><table width=700 border=0>
    <tr><td width=70><font size=2 color=#aaaaaa>编号</font></td>
    <td width=120><font size=2 color=#aaaaaa>IP地址</font></td>
    <td width=200><font size=2 color=#aaaaaa>地域</font></td>
    <td width=80><font size=2 color=#aaaaaa>网页名</font></td>
    <td width=50><font size=2 color=#aaaaaa>次数</font></td>
    <td width=180><font size=2 color=#aaaaaa>最后访问</font></td></tr>
    <?php
    //-------------------------------------------------------------------
    $offset=$page*$pagesize;
    $query44 = "select * from $tablename order by id limit $offset,$pagesize";
    $result44 = mysql_query($query44);
    while($row = mysql_fetch_row($result44)){
    echo "<tr><td><font size=2 color=#000000>".$row[0]."</font></td>";
    echo "<td><font size=2 color=#000000>".$row[2]."</font></td>";
    echo "<td><font size=2 color=#000000>".$row[3]."</font></td>";
    echo "<td><font size=2 color=#000000>".$row[1]."</font></td>";
    echo "<td><font size=2 color=#000000>".$row[4]."</font></td>";
    echo "<td><font size=2 color=#000000>".$row[5]."</font></td></tr>";
    }
    ?>
    <tr><td><font size=2 color=#000000>&nbsp;</font></td>
    <td><font size=2 color=#000000>&nbsp;</font></td>
    <td><font size=2 color=#000000>&nbsp;</font></td>
    <td><font size=2 color=#000000>&nbsp;</font></td>
    <td><font size=2 color=#000000>&nbsp;</font></td>
    <td align=center><font size=2 color=#000000>
    <?php
    if(($page==0))
    {
    echo "<font size=2 color=#000000>首页</font>&nbsp;<font size=2 color=#000000>上页</font>&nbsp;";
    }
    else
    {
    echo "<a target='_self' href=?page=0><font color=blue>首页</font></a>&nbsp;
          <a target='_self' href=?page=".($page-1)."><font color=blue>上页</font></a>&nbsp;";
    }
    if((($page+1)*$pagesize>$total))
    {
    echo "<font size=2 color=#000000>下页</font>&nbsp;<font size=2 color=#000000>末页</font>";
    }
    else
    {
    echo "<a target='_self' href=?page=".($page+1)."><font color=blue>下页</font></a>&nbsp;
    <a target='_self' href=?page=".($totalpage-1)."><font color=blue>末页</font></a>";
    }
    ?></font></td></tr>
    </table><center>
    <?php
    //-------------------------------------------------------------------
    //断开数据库
    mysql_close();
    ?>