多条件查询结果页面分页的问题

WBOY
Release: 2016-06-23 13:53:59
Original
1058 people have browsed it

????????构造查询条件REQ
$show_m_dep=trim($_GET['show_m_dep']);
$show_m_pro=trim($_GET['show_m_pro']);
$show_m_con=trim($_GET['show_m_con']);
$show_m_tim1=trim($_GET['show_m_tim1']);
$show_m_tim2=trim($_GET['show_m_tim2']);
$show_m_kin=trim($_GET['show_m_kin']);

echo $_GET[show_m_pro];
$Req="1";
//构造搜索条件1
if($_GET[show_m_dep]=="99"||empty($_GET[show_m_dep]))
{
//如果为空,查询条件不变
}
else
$Req.=" and M_dep = '$_GET[show_m_dep]'";
//构造搜索条件2
if(empty($_GET[show_m_pro]))
{
//如果为空,搜索条件不变
}
else
$Req.=" and M_pro like '%$_GET[show_m_pro]%'";
//条件3
if(empty($_GET[show_m_con]))
{
//如果为空,搜索条件不变
}
else
$Req.=" and M_con like '%$_GET[show_m_con]%'";
//条件4
$temptime="";
if($_GET[show_m_tim1]!="99"&&(!empty($_GET[show_m_tim1])))
{
    $temptime.=$_GET[show_m_tim1];
if($_GET[show_m_tim2]!="99")
{
$temptime.=$_GET[show_m_tim2];
}
$Req.=" and M_tim like '$_GET[temptime]%'";//只有年份或者年份月份都有
}
//条件5
if($_GET[show_m_kin]=="99"||empty($_GET[show_m_kin]))
{
//如果为空,搜索条件不变
}
else
$Req.=" and M_kin like '$_GET[show_m_kin]'";
$_SESSION[Req]=$Req;
_____________________查询 打印表格内容
$sql="select count(M_id) from myfile WHERE  $Req";
.....
?????????分页页面链接
for($i=1;$i {echo "$i ";
}

____________
大致代码如上,因为构造Req的时候从上一个界面get的内容不一定都能用上,所以最后在分页页面链接中Req感觉没法用几个GET的值来拼出来,用SESSION存似乎也不行,点页码跳转时req又变回初始的1了,因此就想请教一下这种时候查询的条件该怎么写才能在分页页面跳转时保存下来?


回复讨论(解决方案)

你不是已经用 session 保存了吗?

你不是已经用 session 保存了吗?



存了,但是点下面页码链接跳转的时候req的值又回1了..

没有 session_start(); ?
另外,翻页后不再从 $_GET 计算,直接从 session 中取

你在 url 里传了查询条件,那还要保存做什么?
直接 $_GET['Req'] 用就是了

直接用url传参就好了,查询条件和页码都用URL进行传参就好了然后取出来,感觉你还是好好分析下自己要实现的这个功能的逻辑比较好。

检查了每次跳转的URL之后果然发现问题了...
用_server[]获取之前的url解决了问题。感谢上面两位的指点。

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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!