今天做一个分页,遇到一点问题。就是第一页可以正常显示,但是下一页,尾页都无法显示。求解。下面是代码
<?php session_start(); if ($page=="") {$page=1;};if ($ljjl=="") {$ljjl=0;};?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客房状态查询</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
.STYLE2 {font-size: 12px}
.STYLE4 {font-size: 13px}
.STYLE5 {font-family: "华文琥珀"; font-size: 20px;}
-->
</style>
</head>
<body bgcolor="#7791EA">
<table width="500" height="60" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="STYLE5">客房状态查看</td>
</tr>
</table>
<table width="500" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#256B25" valign="middle">
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="100" height="25" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房号码</div></td>
<td width="120" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房类型</div></td>
<td width="100" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房状态</div></td>
<td width="90" bgcolor="#9ABADA"><div align="center" class="STYLE1">容纳人数</div></td>
<td bgcolor="#9ABADA"><div></div></td>
</tr>
<?php
include('include/dbconnect.php');
if($page){
$page_size=10; //每页显示的记录条数
$query="select count(*) as total from roomlist where roomnum"; //从数据库中读取数据
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total"); //获取总的记录数
$page_count=ceil($message_count/$page_size); //获取总的页数
$offset=($page-1)*$page_size;
$sql=mysql_query("select * from roomlist order by roomnum limit $offset, $page_size");
$rs=mysql_fetch_array($sql);
if($rs==false)
{
?>
<tr>
<td height="25" colspan="5" bgcolor="#FFFFFF"><div align="center">没有查找到任何记录!</div></td>
</tr>
<?php
}
else
{
do{
?>
<tr><!--显示查询结果-->
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum];?></div></td> <!--<input type="text" readonly="readonly" value="<?php echo $rs[roomnum];?>" name="roomnum">-->
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[style];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[condition];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[capacities];?></div></td>
<td height="25" bgcolor="#FFFFFF"></td>
</tr>
<?php
}while($rs=mysql_fetch_array($sql));
}
}
?>
</table>
</td>
</tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#9ABADA" align="center">
<tr>
<td width="45%" align="center"><span class="STYLE1"> 页次:<?php echo $page;?>
/ <?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td>
<td width="55%" height="22" align="center"><span class="STYLE1"> 分页:
<?php
if($page!=1)
{
echo "<a href=main_index.php?lm=客房状态查看?page=1>首页</a> ";
echo "<a href=main_index.php?lm=客房状态查看?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=main_index.php?lm=客房状态查看?page=".($page+1).">下一页</a> ";
echo "<a href=main_index.php?lm=客房状态查看?page=".$page_count.">尾页</a>";
}
?>
</span></td>
</tr>
</table>
<table height="80">
<tr><td></td></tr>
</table>
</html>
<?php session_start(); if ($page=="") {$page=1;};if ($ljjl=="") {$ljjl=0;};?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客房状态查询</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
.STYLE2 {font-size: 12px}
.STYLE4 {font-size: 13px}
.STYLE5 {font-family: "华文琥珀"; font-size: 20px;}
-->
</style>
</head>
<body bgcolor="#7791EA">
<table width="500" height="60" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="STYLE5">客房状态查看</td>
</tr>
</table>
<table width="500" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#256B25" valign="middle">
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="100" height="25" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房号码</div></td>
<td width="120" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房类型</div></td>
<td width="100" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房状态</div></td>
<td width="90" bgcolor="#9ABADA"><div align="center" class="STYLE1">容纳人数</div></td>
<td bgcolor="#9ABADA"><div></div></td>
</tr>
<?php
include('include/dbconnect.php');
if($page){
$page_size=10; //每页显示的记录条数
$query="select count(*) as total from roomlist where roomnum"; //从数据库中读取数据
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total"); //获取总的记录数
$page_count=ceil($message_count/$page_size); //获取总的页数
$offset=($page-1)*$page_size;
$sql=mysql_query("select * from roomlist order by roomnum limit $offset, $page_size");
$rs=mysql_fetch_array($sql);
if($rs==false)
{
?>
<tr>
<td height="25" colspan="5" bgcolor="#FFFFFF"><div align="center">没有查找到任何记录!</div></td>
</tr>
<?php
}
else
{
do{
?>
<tr><!--显示查询结果-->
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum];?></div></td> <!--<input type="text" readonly="readonly" value="<?php echo $rs[roomnum];?>" name="roomnum">-->
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[style];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[condition];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[capacities];?></div></td>
<td height="25" bgcolor="#FFFFFF"></td>
</tr>
<?php
}while($rs=mysql_fetch_array($sql));
}
}
?>
</table>
</td>
</tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#9ABADA" align="center">
<tr>
<td width="45%" align="center"><span class="STYLE1"> 页次:<?php echo $page;?>
/ <?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td>
<td width="55%" height="22" align="center"><span class="STYLE1"> 分页:
<?php
if($page!=1)
{
echo "<a href=main_index.php?lm=客房状态查看?page=1>首页</a> ";
echo "<a href=main_index.php?lm=客房状态查看?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=main_index.php?lm=客房状态查看?page=".($page+1).">下一页</a> ";
echo "<a href=main_index.php?lm=客房状态查看?page=".$page_count.">尾页</a>";
}
?>
</span></td>
</tr>
</table>
<table height="80">
<tr><td></td></tr>
</table>
</html>
1.
<?php session_start();$page=intval($_GET['page']); if ($page==0) {$page=1;};if ($ljjl=="") {$ljjl=0;};?>2.
echo "<a href=main_index.php?lm=客房状态查看&page=".($page-1).">上一页</a> ";第二個錯,有些瀏覽器會帶來無法預料的結果
这个$page_size好像是不变的