PHP 查询分页,点击下页 查询变量丢失,求怎么解决?
<!DOCTYPEhtml><htmllang="en"><head><metacharset="gb2312"><title>首页</title><divclass="...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="gb2312">
<title>首页</title>
<div class="container-fluid">
<div class="page-header">
<h1>查询</h1>
<div class="row-fluid">
<form class="well form-search" action="" method="post">
<input type="text" class="input-medium search-query" name="xuesheng_xm" value="张三"/>
<input class="btn" type="submit" value="搜 索"/>
<a href="ddcx.php" class="btn btn-primary pull-right"><i class="icon-pencil icon-white"></i>全部</a>
</form>
</div>
<!--分页开始-->
<!--分页开始-->
<?php
error_reporting(0);
if(isset($_GET['page'])) //由GET方法获得页面传入当前页数的参数
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$page_size = 5; //每页显示两条数据
//获取数据总量
$db_host = 'localhost'; //数据库主机
$db_user = 'root';//数据库用户帐户
$db_passw = '123456'; //数据库帐户密码
$db_name = 'jiaoyou' ;//数据库名称
//连接数据库
$conn=mysql_connect($db_host,$db_user,$db_passw) or die("数据库连接失败!");
//设置字符集,如utf8和gbk等, 根据数据库的字符集而定
mysql_query("set names utf-8");
//选定数据库
mysql_select_db($db_name,$conn) or die('数据库选定失败!');
$xuesheng_xm =$_POST['xuesheng_xm'];//对应姓名
$sql = "select * from biao1 where 1=1 and xuesheng_xm like '%$xuesheng_xm%'";
$resul=mysql_query($sql);
$total = mysql_num_rows($resul);
$start=($page-1)*$page_size;
$result = mysql_query($sql);
//echo $total;
//开始计算总页数
if($total)
{
if($total < $page_size)
$page_count = 1;
if($total % $page_size)
{
$page_count = (int)($total/$page_size) + 1;
}
else
{
$page_count = $total/$page_size;
}
}
else
{
$page_count = 0;
}
//翻页链接
$turn_page = '';
if($page == 1)
{
$turn_page .= '首页 | 上一页 | ';
}
else
{
$turn_page .= '<a href='.$PHP_SELF.'?page=1> 首页</a> | <a href='.$PHP_SELF.'?page='.($page-1).'>上一页</a> |
';
}
if($page == $page_count || $page_count == 0)
{
$turn_page .= '下一页 | 尾页';
}
else
{
$turn_page .= '<a href='.$PHP_SELF.'?page='.($page+1).'>下一页</a> | <a href='.$PHP_SELF.'?
page='.$page_count.'>尾页</a>';
}
$sql = $sql." limit ". ($page-1)*$page_size .", ".$page_size;
echo $sql;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['xuesheng_xm']."</p>";
}
?>
<br />
<?php echo $turn_page?>
</body>
</html> 展开
<html lang="en">
<head>
<meta charset="gb2312">
<title>首页</title>
<div class="container-fluid">
<div class="page-header">
<h1>查询</h1>
<div class="row-fluid">
<form class="well form-search" action="" method="post">
<input type="text" class="input-medium search-query" name="xuesheng_xm" value="张三"/>
<input class="btn" type="submit" value="搜 索"/>
<a href="ddcx.php" class="btn btn-primary pull-right"><i class="icon-pencil icon-white"></i>全部</a>
</form>
</div>
<!--分页开始-->
<!--分页开始-->
<?php
error_reporting(0);
if(isset($_GET['page'])) //由GET方法获得页面传入当前页数的参数
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$page_size = 5; //每页显示两条数据
//获取数据总量
$db_host = 'localhost'; //数据库主机
$db_user = 'root';//数据库用户帐户
$db_passw = '123456'; //数据库帐户密码
$db_name = 'jiaoyou' ;//数据库名称
//连接数据库
$conn=mysql_connect($db_host,$db_user,$db_passw) or die("数据库连接失败!");
//设置字符集,如utf8和gbk等, 根据数据库的字符集而定
mysql_query("set names utf-8");
//选定数据库
mysql_select_db($db_name,$conn) or die('数据库选定失败!');
$xuesheng_xm =$_POST['xuesheng_xm'];//对应姓名
$sql = "select * from biao1 where 1=1 and xuesheng_xm like '%$xuesheng_xm%'";
$resul=mysql_query($sql);
$total = mysql_num_rows($resul);
$start=($page-1)*$page_size;
$result = mysql_query($sql);
//echo $total;
//开始计算总页数
if($total)
{
if($total < $page_size)
$page_count = 1;
if($total % $page_size)
{
$page_count = (int)($total/$page_size) + 1;
}
else
{
$page_count = $total/$page_size;
}
}
else
{
$page_count = 0;
}
//翻页链接
$turn_page = '';
if($page == 1)
{
$turn_page .= '首页 | 上一页 | ';
}
else
{
$turn_page .= '<a href='.$PHP_SELF.'?page=1> 首页</a> | <a href='.$PHP_SELF.'?page='.($page-1).'>上一页</a> |
';
}
if($page == $page_count || $page_count == 0)
{
$turn_page .= '下一页 | 尾页';
}
else
{
$turn_page .= '<a href='.$PHP_SELF.'?page='.($page+1).'>下一页</a> | <a href='.$PHP_SELF.'?
page='.$page_count.'>尾页</a>';
}
$sql = $sql." limit ". ($page-1)*$page_size .", ".$page_size;
echo $sql;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['xuesheng_xm']."</p>";
}
?>
<br />
<?php echo $turn_page?>
</body>
</html> 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询