Home > Backend Development > PHP Tutorial > (急)PHP + MYSQL查询结果分页显示有关问题

(急)PHP + MYSQL查询结果分页显示有关问题

WBOY
Release: 2016-06-13 10:24:23
Original
1483 people have browsed it

(急!!)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 .= '下一页|末页';
}
?>


  $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))
{
?>

".$myrow[1].""."".""."".""."".""."";?>
 

".$myrow[2]."".$myrow[3]."".$myrow[4]."".$myrow[5]."".$myrow[6].""."详细"." (急)PHP + MYSQL查询结果分页显示有关问题(急)PHP + MYSQL查询结果分页显示有关问题




总共".$amount."";?>条记录

echo "共"." ".$page_count." "."页(".$page."/".$page_count.")"." ".$page_string;
?>
跳到





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template