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

2024-11-23 09:14:18
推荐回答(5个)
回答1:

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 "";
}
$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))
{
?>


  • Gzxx"?> Gzsj"?>

  • Daiyu"?>

  • 管理员回复:Adddate"?>


}
if ($page != 1) { //页数不等于1
?>


上一页
}
for ($i=1;$i<=$totalPage;$i++) { //循环显示出页面
?>

}
if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
?>
下一页
}
?>

回答2:

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 "";
}
$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))
{
?>


  • Gzxx"?> Gzsj"?>

  • Daiyu"?>

  • 管理员回复:Adddate"?>


}
if ($page != 1) { //页数不等于1
?>


上一页
}
for ($i=1;$i<=$totalPage;$i++) { //循环显示出页面
?>

}
if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
?>
下一页
}
?>

回答3:

只需要把你的所查询的参数放到 分页中就可以了!device_list.php?page=$i& (在这加查询参数)

回答4:

把你要查询的参数构成一个url.php?a=aa&b=bb&c=www.111cn.net
这种,再利用php获取查询分页就KO了。

回答5:

你在分页时,应该把多条件查询的条件,也就是参数一同通过变量传递下去。