当前位置:Gxlcms > PHP教程 > PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容

PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容

时间:2021-07-01 10:21:17 帮助过:19人阅读

背景:在一ldt.php页面中有同一个form,两个按钮分别在提交的时候给到两个不同页面。一个按钮是插入数据库,一个按钮是查询并提交给自己在本页中展示出结果内容,有分页函数,提交后跳转过来的第一页是正常显示查询条件对应的结果的,但是点击下一页等就会显示数据库全部结果。我觉得应该是分页的时候没有带上参数,但是不知道怎么带,把部分源代码贴上来,请大神修改一下。
1、js提交不同页面:


2、分页函数:

$page = $_GET["page"];
function Page($rows,$page_size){
global $page,$select_from,$select_limit,$pagenav;
$page_count = ceil($rows/$page_size);
if($page <= 1 || $page == '') $page = 1;
if($page >= $page_count) $page = $page_count;
$select_limit = $page_size;
$select_from = ($page - 1) * $page_size.',';
$pre_page = ($page == 1)? 1 : $page - 1;
$next_page= ($page == $page_count)? $page_count : $page + 1 ;
$pagenav .= "第 $page/$page_count 页 共 $rows 条记录 ";
$pagenav .= "首页 ";
$pagenav .= "前一页 ";
$pagenav .= "后一页 ";
$pagenav .= "末页";
$pagenav.=" 跳到\n";
for($i=1;$i<=$page_count;$i++){
if($i==$page) $pagenav.="\n";
else $pagenav.="\n";
}
} // Page分页函数
// 使用示例
if (!$conn= mysql_connect("localhost", "r12" ,"22222")) die('数据库选择失败!');
if (!mysql_select_db("ccccccc", $conn)) die('数据库选择失败!');
// 用Page函数计算出 $select_from 从哪条记录开始检索、$pagenav 输出分页导航
$sqlv = "SELECT
max(dtime) as dtime
FROM
haocai
where scene='VIP耗材'
ORDER BY
dtime DESC ";
$rstv = mysql_query($sqlv,$conn);
$rowv=mysql_fetch_assoc($rstv);

$sqlp = "SELECT
max(dtime) as dtime
FROM
haocai
where scene='普通耗材'
ORDER BY
dtime DESC ";
$rstp = mysql_query($sqlp,$conn);
$rowp=mysql_fetch_assoc($rstp);



//任意条件查询组合






if(!empty($hcrdtbj))
{

if(strstr($hcrdtbj,"VIP耗材"))
{
$hcr=substr($hcrdtbj, 9);
$scener=mb_substr($hcrdtbj, 0, 5, 'utf-8');
}
else
{
$hcr=substr($hcrdtbj,12);
$scener=mb_substr($hcrdtbj, 0, 4, 'utf-8');
}


$a="where scene='$scener' and hc='$hcr'";
$_SESSION['where']= "where scene='$scener' and hc='$hcr'";
}



else{

if($_POST['customer']=="用户名" && !empty($_POST['scene']) && !empty($_POST['purpose'])&& !empty($_POST['catalogue'])&& !empty($_POST['hc'])&& $_POST['reason']!=="原因"){


$a="where scene='$_POST[scene]' and purpose='$_POST[purpose]' and catalogue='$_POST[catalogue]' and hc='$_POST[hc]' and reason='$_POST[reason]'";
$_SESSION['where']="where scene='$_POST[scene]' and purpose='$_POST[purpose]' and catalogue='$_POST[catalogue]' and hc='$_POST[hc]' and reason='$_POST[reason]'";
$_SESSION['hcrdtbj']="$_POST[scene]$_POST[purpose]$_POST[catalogue]$_POST[hc]$_POST[reason]";

}


else{


$a="";
$_SESSION['where']="order by dtime desc";

}
}









$rows = mysql_num_rows(mysql_query("select customer,scene,purpose,catalogue,hc,number,reason,person,dtime from haocai $a "));
Page($rows,35);



$sql = "select customer,scene,purpose,catalogue,hc,number,reason,person,dtime from haocai $a order by scene,dtime desc limit $select_from $select_limit ";
$rst = mysql_query($sql);
while($row=mysql_fetch_assoc($rst)){

$vip_style = $row['scene']=="VIP耗材" ? ' style=" background-color:#096;color:white;"' : '';


echo "{$row['customer']}{$row['scene']}{$row['purpose']}{$row['catalogue']}";

if($row['scene']=="VIP耗材"){
echo "的库存详情' style='color:white;'/a>{$row['hc']}";}
else{
echo "的库存详情'/a>{$row['hc']}";}

echo "{$row['number']}{$row['reason']}{$row['person']}";

if($row['dtime'] ==$rowv['dtime'] || $row['dtime'] ==$rowp['dtime'] ) {

echo "{$row['dtime']}";

}
else{

echo "{$row['dtime']}";

}


}
echo "$pagenav";
mysql_close($conn);
mysql_free_result($rst);
mysql_free_result($rstv);
mysql_free_result($rstp);





?>










           领用详情库存详情      = $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size.','; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; $pagenav .= "首页 "; $pagenav .= "前一页 "; $pagenav .= "后一页 "; $pagenav .= "末页"; $pagenav.=" 跳到";if($row['scene']=="VIP耗材"){echo "";}else{echo "";}echo "";if($row['dtime'] ==$rowv['dtime'] || $row['dtime'] ==$rowp['dtime'] ) {echo "";}else{echo "";	}	} echo "";mysql_close($conn);mysql_free_result($rst);mysql_free_result($rstv);mysql_free_result($rstp); ?>
用户名归属场景类型明细领用数原因操作人时间
{$row['customer']}{$row['scene']}{$row['purpose']}{$row['catalogue']}的库存详情' style='color:white;'/a>{$row['hc']}的库存详情'/a>{$row['hc']}{$row['number']}{$row['reason']}{$row['person']}{$row['dtime']}
{$row['dtime']}
$pagenav

人气教程排行