哪位高手帮我看看,为什么不能实现跳转到下一页或者上一页

来源:互联网 发布:网络硬盘存储器 编辑:程序博客网 时间:2024/04/30 05:36
<?php
include("conn.php");
$sql="select count(*) as total from message order by id desc"; //查询出总的数据记录的条数,赋值给total
$result=mysql_query($sql);
$page=intval($page);
if($page=="")      //$page为当前页,如果$page为空,则初始化为1
{
 $page=1;
 }
if(is_numeric($page)){        //判断变量$page是否为数字,如果是则返回true
 $page_size=8;                     // 每页显示6条记录
 $message_count=mysql_result($result,0,"total");  // 查询符合条件的记录总条数
 $page_count=ceil($message_count/$page_size);    // 由记录总数除以每页显示的记录数==页数
 $offset=($page-1)*$page_size;    //计算下一页从第几条数据开始循环
 $query=mysql_query("select * from message order by id limit $offset,$page_size");               
}
if(mysql_num_rows($query)>0)
{
?>
<style type="text/css">
 table{
  width:960px;
  height:auto;
 }
 td{
  width:90px;
 height:24px;
 line-height:24px;
 }
 #content{
  width:600px;
 }
 </style>
<table  border="1"align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#999999">
 <tr><th>留言编号</th><th>用户名</th><th>标题</th><th>内容</th><th>时间</th></tr>
 <?php
 while($row=mysql_fetch_assoc($query))
 {
  ?>
  <tr><td><?php echo $row['id'] ;?></td>
   <td><?php echo $row['user'] ;?></td>
   <td><?php echo $row['title'] ;?></td>
   <td id="content"><?php echo $row['content'] ;?></td>
   <td><?php echo $row['time'] ;?></td>
   </tr>
 <?php
 }
}
else
{
 echo '<script language="javascript">alert("还没有留言");</script>';
}
?>
</table>
<table border="0" cellspacing="0" cellpadding="0" align="center">
 <tr>
  <!--翻页条-->
  <td width="37%" align="right">&nbsp;&nbsp;页次:<?php echo $page;  ?>/<?php echo $page_count; ?>页&nbsp;记录:<?php echo $message_count; ?>条&nbsp;</td>
   <td width="63%" align="left">
   <?php
   /* 如果当前页不是首页*/
   if($page!=1){
    /* 显示"首页"超链接*/
    echo "<a href=\"chakan.php?page=1\">首页</a>&nbsp;";
    /*显示”上一页“的超链接*/
    echo "<a href=\"chakan.php?page=".($page-1)."\">上一页</a>&nbsp;";
   }
   /*如果当前不是尾页*/
   if($page< $page_count){
    /* 显示“下一页”超链接 */
    echo "<a href=\"chakan.php?page=".($page+1)."\">下一页</a>&nbsp;";
    /* 显示“尾页”超链接 */
    echo "<a href='chakan.php?page=".$page_count."'>尾页</a>";
   }
   mysql_free_result($query);
   mysql_close($conn);
   ?>
    </td>
  </tr>
 </table>
原创粉丝点击