PHP實現多條件查詢執行個體代碼_php執行個體

來源:互聯網
上載者:User
查詢檔案(search.php)
一、產生查詢語句:

複製代碼 代碼如下:

<?
$conn=mysql_connect("localhost","root","");
$db=mysql_select_db("lingyun");
$query="select * from message where tradetype='".$tradetype."'"; //交易類型,如出租,出售
$SQL=$SQL . "wuye='" . $wuye . "'";
if($housetype!="不限"){
$query.=" && housetype='".$housetype."'"; //房屋類型,如二室一廳,三室二廳
}
if($degree!="不限"){
$query.=" && degree='".$degree."'"; //新舊程度
}
if($wuye!="不限"){
$query.=" && wuye='".$wuye."'"; //物業類型 如房屋,商鋪
}
if($price2!=""){
switch($price1){
case "大於":
$query.=" && price>'".$price2."'"; //價格
break;
case "等於":
$query.=" && price='".$price2."'";
break;
case "小於":
$query.=" && price<'".$price2."'";
break;
}
}
if($area2!=""){
switch($area1){
case "大於":
$query.=" && area>'".$area2."'"; //面積
break;
case "等於":
$query.=" && area='".$area2."'";
break;
case "小於":
$query.=" && area<'".$area2."'";
break;
}
}
switch($pubdate){ //發布日期
case "本星期內":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=7";
break;
case "一個月內":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=30";
break;
case "三個月內":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=91";
break;
case "六個月內":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=183";
break;
}
if($address!=""){
$query.=" && address like '%$address%'"; //地址
}
if(!$page){
$page=1;
}
?>


二、輸出查詢結果:
複製代碼 代碼如下:

<?php
if ($page){
$page_size=20;
$result=mysql_query($query);
#$message_count=mysql_result($result,0,"total");
$message_count=10;
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query=$query." order by date desc limit $offset, $page_size";
$result=mysql_query($query);
if($result){
$rows=mysql_num_rows($result);
if($rows!=0){
while($myrow=mysql_fetch_array($result)){
echo "<tr>";
echo "<td width='15' height='12'><img src='image/home2.gif' width='14' height='14'></td>";
echo "<td width='540' height='12'>$myrow[id] $myrow[tradetype] $myrow[address] $myrow[wuye]($myrow[housetype])<font style='font-size:9pt'>[$myrow[date]]</font>";
echo "</td>";
echo "<td width='75' height='12'><a href='view_d.php?code=$myrow[code]' target='_blank'>詳細內容</a></td>";
echo "</tr>";
}
}
else echo "<tr><td><div align='center'><img src='image/sorry.gif'><br><br>沒有找到滿足你條件的記錄</div>& lt;/td></tr>";
}
$prev_page=$page-1;
$next_page=$page 1;
echo "<div align='center'>";
echo " 第".$page."/".$page_count."頁 ";
if ($page<=1){
echo "|第一頁|";
}
else{
echo "<a href='$PATH_INFO?page=1'>|第一頁|</a>";
}
echo " ";
if ($prev_page<1){
echo "|上一頁|";
}
else{
echo "<a href='$PATH_INFO?page=$prev_page'>|上一頁|</a>";
}
echo " ";
if ($next_page>$page_count){
echo "|下一頁|";
}
else{
echo "<a href='$PATH_INFO?page=$next_page'>|下一頁|</a>";
}
echo " ";
if ($page>=$page_count){
echo "|最後一頁|";
}
else{
echo "<a href='$PATH_INFO?page=$page_count'>|最後一頁|</a>";
}
echo "</div>";
}
else{
echo "<p align='center'>現在還沒有房屋租賃資訊!</p>";
}
echo "<hr width="100%" size="1">";
?>
</table>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.