关于php多条件模糊查询后分页问题!

/*分页------------------------------------------------------------------------*/$page=$... /*分页------------------------------------------------------------------------*/
$page = $_GET['page']; //取得url参数
$count = "select count(*) from oems_device_baseinfo";
$rs = $db->fetch($count);
$totalNumber=$rs['count(*)']; //总记录条数
$perNumber = 10;
$totalPage=ceil($totalNumber/$perNumber); //总页数
if ($page<=1 && empty($page)) {
$page=1; //刚进来时赋初值1
}
$startCount=($page-1)*$perNumber;
/*搜索------------------------------------------------------------------------*/
$look_type = $_GET['type'];
$look_status = $_GET['status'];
$look_coder = $_GET['coder'];
$lookup = "select * from oems_device_baseinfo";
if(!empty($look_type)){
$lookup .= " where type like '%$look_type%'";
if(!empty($look_status)){
$lookup .= " and status = $look_status";
}
}else if(!empty($look_status)){
$lookup .= " where status like $look_status";
}else if(!empty($look_coder)){
$look=addslashes($look_coder);
$look=trim($look_coder);
$lookup .= " where coder like '%$look_coder%'";
}
$lookup .= " order by did desc limit $startCount,$perNumber ";
//$result = "select * from oems_device_baseinfo order by did desc limit $startCount,$perNumber";
$db->results($lookup);
以上是php分页及搜索代码

<select name='type'>
<option value=''>--设备类型--</option>
<?php
foreach($type_arr as $key=>$val){
?>
<option value='<?=$key?>'><?=$val?></option>
<?php
}
?>
</select>    
</td>
<td width='130'>
<select name='status'>
<option value=''>--设备状态--</option>
<?php
foreach($device_status_arr as $key=>$val){
?>
<option value='<?=$key?>'><?=$val?></option>
<?php
}
?>
</select>
以上是多条件模糊查询,显示在页面上的

<tr align="right" bgcolor="#EEF4EA">
<td height="36" colspan="14" align="center">
<?php
echo "当前第<".$page.">页";
if ($page != 1) { //当当前页不是第一页时`显示上一页
?>
<a href="device_list.php?page=<?php echo $page - 1;?>">上一页</a>
<?php
}
for ($i=1;$i<=$totalPage;$i++) { //输出第123456页
echo "<a href=\"device_list.php?page=$i\" >$i <a>";
}
if ($page<$totalPage) //如果当前页小于最大页`显示下一页
{
$page=$page+1;
echo "
<a href=\"device_list.php?page=$page\">下一页<a>";
}
?>
</td>
</tr>
以上是显示在页面上的分页代码? 目前可以正常分页,可是我做了多条件查询后却不只该怎么显示出搜索后的记录分页; 希望高手给予指点!!小弟在此多谢了;
能具体一点吗,拿我的代码为例,举个实例!
展开
 我来答
郭某人来此
2015-09-13 · TA获得超过1645个赞
知道答主
回答量:952
采纳率:100%
帮助的人:89.4万
展开全部
<?php
define('IN_JOBS', true);
require_once("./cc_include/common.php");
require_once("./cc_include/page.class.php");
require_once("./cc_include/page_function.php");

require_once("./cc_include/Site_Config.php");

//加载smarty模板
$smarty = new Smarty();
$smarty->template_dir="./templates/default/";
$smarty->compile_dir="./templates_c/default/";
$smarty->cache_dir=CACHE_PATH;
$smarty->left_delimiter="{*";
$smarty->right_delimiter="*}";
$smarty->caching=false;
//开始跑首页信息
$Gonggao=News(1, 5);
//以上信息为公告和右侧的两个新闻

if (isset($_GET['sousuo'])) $searchname = $_GET['sousuo'];//得到搜索关键词
else if (isset($_POST['sousuo'])) $searchname = $_POST['sousuo'];

if(!isset($searchname))
{
echo "<script>location.href='index.php';</script>";
}
$typename=$_POST['type'];
$shijian=$_POST['rboname'];
$xitongshijian=date("Y-m-d");//获得系统当前时间
$jianyitian=date('Y-m-d H:i:s',strtotime("$a-1 day"));//减去一天时间

$jiansantian=date('Y-m-d',strtotime("$a-3 day"));//减去三天时间

$jianqitian=date('Y-m-d',strtotime("$a-7 day"));//减去7天时间

switch($typename)
{
case "职位名":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' order by Adddate desc";

}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
case "工作时间":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' order by Adddate desc";
}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
}

$perNumber=5; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值
$count=mysql_query("select count(*) from ejz_wor where ".$tiaojian.""); //获得记录总数

$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
if (!isset($page)) {
$page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
$sql="select Wor_id,Gzxx,Zprs,Gzsj,Gzyq,Daiyu,Adddate,jipin from ejz_wor where ".$tiaojian." limit $startCount,$perNumber";
$result=mysql_query($sql);
while ($row=mysql_fetch_object($result))
{
?>
<ul>
<li><div class="kf_xian" align="left"><? echo "$row->Gzxx"?> <a href="#" style="text-align:left"><? echo "$row->Gzsj"?></a></div></li>
<li><? echo "$row->Daiyu"?></li>
<li>管理员回复:<? echo "$row->Adddate"?></li>
</ul>
<?
}
if ($page != 1) { //页数不等于1
?>

<?php echo "总共".$totalPage."页,";?>
<a href="wj.php?page=<?php echo $page - 1;?>&sousuo=<?php echo $searchname;?>">上一页</a> <!--显示上一页-->
<?php
}
for ($i=1;$i<=$totalPage;$i++) { //循环显示出页面
?>
<a href="wj.php?page=<?php echo $i;?>&sousuo=<?php echo $searchname;?>"><?php echo $i ;?></a>
<?php
}
if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
?>
<a href="wj.php?page=<?php echo $page + 1;?>&sousuo=<?php echo $searchname;?>">下一页</a>
<?php
}
?>
圣鸾OJ
2015-09-29 · TA获得超过1629个赞
知道小有建树答主
回答量:1136
采纳率:96%
帮助的人:112万
展开全部
<?php
define('IN_JOBS', true);
require_once("./cc_include/common.php");
require_once("./cc_include/page.class.php");
require_once("./cc_include/page_function.php");

require_once("./cc_include/Site_Config.php");

//加载smarty模板
$smarty = new Smarty();
$smarty->template_dir="./templates/default/";
$smarty->compile_dir="./templates_c/default/";
$smarty->cache_dir=CACHE_PATH;
$smarty->left_delimiter="{*";
$smarty->right_delimiter="*}";
$smarty->caching=false;
//开始跑首页信息
$Gonggao=News(1, 5);
//以上信息为公告和右侧的两个新闻

if (isset($_GET['sousuo'])) $searchname = $_GET['sousuo'];//得到搜索关键词
else if (isset($_POST['sousuo'])) $searchname = $_POST['sousuo'];

if(!isset($searchname))
{
echo "<script>location.href='index.php';</script>";
}
$typename=$_POST['type'];
$shijian=$_POST['rboname'];
$xitongshijian=date("Y-m-d");//获得系统当前时间
$jianyitian=date('Y-m-d H:i:s',strtotime("$a-1 day"));//减去一天时间

$jiansantian=date('Y-m-d',strtotime("$a-3 day"));//减去三天时间

$jianqitian=date('Y-m-d',strtotime("$a-7 day"));//减去7天时间

switch($typename)
{
case "职位名":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' order by Adddate desc";

}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
case "工作时间":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' order by Adddate desc";
}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
}

$perNumber=5; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值
$count=mysql_query("select count(*) from ejz_wor where ".$tiaojian.""); //获得记录总数

$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
if (!isset($page)) {
$page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
$sql="select Wor_id,Gzxx,Zprs,Gzsj,Gzyq,Daiyu,Adddate,jipin from ejz_wor where ".$tiaojian." limit $startCount,$perNumber";
$result=mysql_query($sql);
while ($row=mysql_fetch_object($result))
{
?>
<ul>
<li><div class="kf_xian" align="left"><? echo "$row->Gzxx"?> <a href="#" style="text-align:left"><? echo "$row->Gzsj"?></a></div></li>
<li><? echo "$row->Daiyu"?></li>
<li>管理员回复:<? echo "$row->Adddate"?></li>
</ul>
<?
}
if ($page != 1) { //页数不等于1
?>

<?php echo "总共".$totalPage."页,";?>
<a href="wj.php?page=<?php echo $page - 1;?>&sousuo=<?php echo $searchname;?>">上一页</a> <!--显示上一页-->
<?php
}
for ($i=1;$i<=$totalPage;$i++) { //循环显示出页面
?>
<a href="wj.php?page=<?php echo $i;?>&sousuo=<?php echo $searchname;?>"><?php echo $i ;?></a>
<?php
}
if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
?>
<a href="wj.php?page=<?php echo $page + 1;?>&sousuo=<?php echo $searchname;?>">下一页</a>
<?php
}
?>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xxffeecc
2010-11-05
知道答主
回答量:32
采纳率:0%
帮助的人:18.9万
展开全部
只需要把你的所查询的参数放到 分页中就可以了!device_list.php?page=$i& (在这加查询参数)
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
智财商言
2010-11-04 · TA获得超过188个赞
知道小有建树答主
回答量:577
采纳率:52%
帮助的人:144万
展开全部
把你要查询的参数构成一个url.php?a=aa&b=bb&c=www.111cn.net
这种,再利用php获取查询分页就KO了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
小豆丁童装店
2010-11-03
知道答主
回答量:5
采纳率:0%
帮助的人:0
展开全部
你在分页时,应该把多条件查询的条件,也就是参数一同通过变量传递下去。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式