⑴ 关于php多条件模糊查询后分页问题!
<?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
}
?>
⑵ php 多条件查询数据库MySQL
SELECT * FROM `表名` WHERE bookid=22
获取BOOKID为22的记录,输出$uid=
if(strpos($uid,"2")!==false):echo"包含";else:echo"不包含";endif;
判断UID中是否含有2
MYSQLI方法统计数量
$num=mysqli_num_rows(mysqli_query($mysqli,"SELECT id FROM `表名` where pinglun=1"));
统计该表中pinglun=1的记录数量
⑶ thinkphp where有多个条件进行复合查询,关系为or,代码如下
请参考thinkphp开发手册的查询语言一节,可以有不同写法,我这里写一种供你参考:
$where1=array(
'Key'=>array('like','zt'.'%'),
'code'=>'02'
);
$where=array(
'modes'=>1,
'Key'=>array('like','tm'.'%'),
'code'=>'02',
'_complex'=>$where1,//复合查询
'_logic'=>'or'//关系为or
);
//查询语句
$mysql=M('Mysql')->where($where)->select();