Maison > Article > développement back-end > (急)PHP + MYSQL查询结果分页显示有关问题
(急!!)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_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 .= '首页|上一页|';
}
if( ($page == $page_count) || ($page_count == 0) )
{
$page_string .= '下一页|末页';
}
else
{
$page_string .= '下一页|末页';
}
?>
".$myrow[2]." | "."".$myrow[3]." | "."".$myrow[4]." | "."".$myrow[5]." | "."".$myrow[6]." | ".""."详细"." | "." | ";?> |
|