⑴ 關於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();