相同的方法做其他的页面一点问题没有,但是这个页面点下一页的时候却是空的只贴关键部分
<?php session_start();$page=intval($_GET['page']); if ($page=="") {$page=1;}?>
下面这段是SQL语句部分。
<?php
include('include/dbconnect.php');
$a="$_POST[timeform]";
$b="$_POST[timeto]";
$c=strtotime($a."00:00");
$d=strtotime($b."23:59:59");
if($page){
$page_size=10; //每页显示的记录条数
$query="select count(*) as total from account where checktime between '$c' and '$d'"; //从数据库中读取数据
$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 `account` where checktime between '$c' and '$d' order by a_id 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[a_id];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[cost];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo date('Y-m-d H:i',$rs[checktime]);?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[opname];?></div></td>
</tr>
<?php
}while($rs=mysql_fetch_array($sql));
}
?>
下面是分页显示部分<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=财务报表查看1>首页</a> ";
echo "<a href=main_index.php?lm=财务报表查看1&page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=main_index.php?lm=财务报表查看1&page=".($page+1).">下一页</a> ";
echo "<a href=main_index.php?lm=财务报表查看1&page=".$page_count.">尾页</a>";
}
?>
</span></td>
第一页显示正常的 但是点下一页是空的 没有任何结果
<?php session_start();$page=intval($_GET['page']); if ($page=="") {$page=1;}?>
下面这段是SQL语句部分。
<?php
include('include/dbconnect.php');
$a="$_POST[timeform]";
$b="$_POST[timeto]";
$c=strtotime($a."00:00");
$d=strtotime($b."23:59:59");
if($page){
$page_size=10; //每页显示的记录条数
$query="select count(*) as total from account where checktime between '$c' and '$d'"; //从数据库中读取数据
$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 `account` where checktime between '$c' and '$d' order by a_id 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[a_id];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[cost];?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo date('Y-m-d H:i',$rs[checktime]);?></div></td>
<td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[opname];?></div></td>
</tr>
<?php
}while($rs=mysql_fetch_array($sql));
}
?>
下面是分页显示部分<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=财务报表查看1>首页</a> ";
echo "<a href=main_index.php?lm=财务报表查看1&page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=main_index.php?lm=财务报表查看1&page=".($page+1).">下一页</a> ";
echo "<a href=main_index.php?lm=财务报表查看1&page=".$page_count.">尾页</a>";
}
?>
</span></td>
第一页显示正常的 但是点下一页是空的 没有任何结果
$a="$_POST[timeform]"; // $a=0
$b="$_POST[timeto]"; // $b=0
我猜想,你應該是提交一個表單之後能夠顯示第一頁
但你的下一頁並不是表單提交後得到的, 所以$_POST 是為空的如果是這樣的話,解決的方法很簡單
你把表單的method 改為 GET
再把相應的POST 都改成GET, 就行了
$a="$_GET[timeform]";
$b="$_GET[timeto]";
<tr>
<td bgcolor="#9ABADA" class="noprint"><div align="center">选择时间段:
<input type="text" name="timeform" size="20" class="inputcss" readonly="readonly" /><img src="image/date.gif" width="20" height="20" onClick="open_day_from()"/>
到<input type="text" name="timeto" size="20" class="inputcss" readonly="readonly" /><img src="image/date.gif" width="20" height="20" onClick="open_day_to()"/>
<input type="submit" name="submit" value="查询" class="buttoncss" onclick="return check(form1);"></div>
</td>
</tr>
</form> 如果直接改成GET,那个跳转的时候直接变成跳到main_index.php?timeform=''&timeto=''...之类的lm=财务报表查看就直接被覆盖掉了
lm=财务报表查看1 你可以不帶在action 後面啊
寫成<input type="hidden" name="lm" value="财务报表查看1" />如果你堅持要用POST
那就用
$a="$_REQUEST[timeform]";
$b="$_REQUEST[timeto]";兩種方法隨你選
然後剛還忘了
在分頁的鏈接處,也要帶上ml,timefrom, timeto, page 等你需要的參數
地址栏是这样的http://localhost/ktv/main_index.php?lm=财务报表查看&timeform=2010-1-1&timeto=2036-1-1&page=2 下面是空白的
我是用了 $a="$_REQUEST[timeform]";
$b="$_REQUEST[timeto]";
看看是哪個值拿不到
如果都拿到了
打印一下 $page 值是不是正確的如果沒問題
再打印一下你的兩個sql 語句,看有沒有問題
如果沒問題,就 拿到mysql 下運行, 看能不能正確查詢總之就是一步一步下來...