时间:2021-07-01 10:21:17 帮助过:16人阅读
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
$sql="SELECT count(*) from khxx";
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";
if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ;
$wh="where {$ww}";
}
echo "首页";
echo "上一页";
echo "下一页";
echo "末页";
?>
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ";
$wh="where {$ww}";
}else{
$wh = ""
}
$sql="SELECT count(*) from khxx ".$wh; // 计算总数时加入搜索条件
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";
// 查询当前页记录
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>
echo "上一页";
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ";
$wh="where {$ww}";
}else{
$wh = ""
}
$sql="SELECT count(*) from khxx ".$wh; // 计算总数时加入搜索条件
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";
// 查询当前页记录
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>
效果和我写的差不多
我写的有个问题就是 点下一页后 当前的查询状态就消失了 想问下 怎么写才可以把查询加入到分页