導航:首頁 > 編程語言 > phpwhere多條件查詢

phpwhere多條件查詢

發布時間:2022-12-24 14:16:10

⑴ 關於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();
閱讀全文

與phpwhere多條件查詢相關的資料

熱點內容
肌肉塑造全書pdf下載 瀏覽:796
安卓簡約拼圖用什麼軟體好 瀏覽:289
fx1n加密程序 瀏覽:844
淘客阿里雲伺服器 瀏覽:476
100壓縮打造 瀏覽:422
安卓手機怎麼和蘋果平板傳文件 瀏覽:973
開始選項卡中的頁眉和頁腳命令選項 瀏覽:424
pdf的字體怎麼改 瀏覽:856
python讀寫視頻 瀏覽:88
科魯茲壓縮機軸承 瀏覽:353
word文檔轉換成pdf文件找不到 瀏覽:27
組件注冊命令 瀏覽:760
安卓大屏導航用的是什麼運放 瀏覽:443
myandroidtools的備份 瀏覽:900
python爬蟲天氣預報 瀏覽:761
android70許可權管理 瀏覽:749
魔獸辛迪加是什麼伺服器 瀏覽:472
電腦文件夾排序怎麼自定義排序 瀏覽:41
android70機型 瀏覽:422
阿里程序員地位 瀏覽:183