(急!!)PHP + MYSQL查询结果分页显示问题
include_once ("./config.php");
db_connect();
// 获取当前页数
if( isset($_POST['page']) )//判断是否有下面的表单post来的值
{
$page=$_POST['page'];
}
else if(isset($_GET['page']))//判断是否有get来的值
{
$page = intval( $_GET['page'] );
}
else
{
$page = 1;
}
// 每页数量
$page_size = 10;
$devicename=$_POST["textname"];
if($_POST[Submit]!="")
{
$sql = "select count(*) as amount from labdeviceinfo where DeviceName='$devicename'";
}
else
{
$sql = "select count(*) as amount from labdeviceinfo";
}
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$amount = $row[0];// 获取总数据量
// 记算总共有多少页
if( $amount )
{
if( $amount < $page_size )//如果总数据量小于$PageSize,那么只有一页
{
$page_count = 1;
}
if( $amount % $page_size ) //取总数据量除以每页数的余数
{
$page_count = (int)($amount / $page_size) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一
}
else
{
$page_count = $amount / $page_size; //如果没有余数,则页数等于总数据量除以每页数的结果
}
}
else
{
$page_count = 0;
}
// 翻页链接
$page_string = '';
if( $page == 1)
{
$page_string .= '首页|上一页|';
}
else
{
$page_string .= '<a href=?page=1>首页</a>|<a href=?page='.($page-1).'>上一页</a>|';
}
if( ($page == $page_count) || ($page_count == 0) )
{
$page_string .= '下一页|末页';
}
else
{
$page_string .= '<a href=?page='.($page+1).'>下一页</a>|<a href=?page='.$page_count.'>末页</a>';
}
?>
<table>
<?php
$server=$_SERVER['PHP_SELF'];
$start=($page-1)*$page_size;
if (($_POST[Submit]!=""||$_POST[textname]))
{
$devicename=$_POST["textname"];
$sqlquery="select * from labdeviceinfo where DeviceName='$devicename' limit $start , $page_size";
}
else
{
$sqlquery="select * from labdeviceinfo limit $start , $page_size";
}
$myresult=mysql_query($sqlquery);
while($myrow = mysql_fetch_array($myresult))
{
?>
<tr align="center">
<?php echo "<td>".$myrow[1]."</td>"."<td>".$myrow[2]."</td>"."<td>".$myrow[3]."</td>"."<td>".$myrow[4]."</td>"."<td>".$myrow[5]."</td>"."<td>".$myrow[6]."</td>"."<td>"."<a href='detail.php'>详细</a>"."<td><img src='img/edit.gif'></td>"."<td><img src='img/del.gif'></td>";?>
</tr>
<?php } ?>
</table>
<table width="100%" style="margin-left:5%;">
<tr><form method="post"><td colspan="3" align="center">
总共<?php echo "<font color='#CC0033'>".$amount."</font>";?>条记录
<?php
echo "共"." ".$page_count." "."页(".$page."/".$page_count.")"." ".$page_string;
?>
跳到<input type="text" name="page" value="1" size="2" />页
<input type="submit" value="go" />
</td></form></tr></table>
<table><tr><td>
<