導航:首頁 > 編程語言 > 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多條件查詢相關的資料

熱點內容
自駕車跑腿哪個app好 瀏覽:199
騰訊雲校園伺服器已認證 瀏覽:790
如何解開應用加密 瀏覽:902
考研詞彙劉一男pdf 瀏覽:119
kali的內核頭編譯 瀏覽:867
數控銑床洗斜面怎麼編程 瀏覽:894
程序員基礎架構崗怎麼樣 瀏覽:412
有什麼好的付費app 瀏覽:626
java生成6隨機數字 瀏覽:177
匯編語言程序設計教程pdf 瀏覽:44
我的老公是冥王在哪個app上看 瀏覽:70
程序員婚前准備 瀏覽:372
金鏟鏟之戰微信安卓兌換碼怎麼換 瀏覽:846
單片機38解碼器 瀏覽:335
思域換壓縮機 瀏覽:183
必應伺服器ip地址 瀏覽:628
魔獸世界伺服器怎麼連接 瀏覽:39
什麼地方會用到雲伺服器 瀏覽:54
pdfarchitect 瀏覽:676
圖片找不到文件夾 瀏覽:199