PHP实现多条件查询实例代码

前端之家收集整理的这篇文章主要介绍了PHP实现多条件查询实例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

查询文件(search.PHP

一、生成查询语句:

<div class="codetitle"><a style="CURSOR: pointer" data="55076" class="copybut" id="copybut55076" onclick="doCopy('code55076')"> 代码如下:
<div class="codebody" id="code55076">
<?
$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;
}
?>

二、输出查询结果:


<div class="codetitle"><a style="CURSOR: pointer" data="46790" class="copybut" id="copybut46790" onclick="doCopy('code46790')"> 代码如下:
<div class="codebody" id="code46790">
<?PHP
if ($page){
$page_size=20;
$result=MysqL_query($query);
#$message_count=MysqL_result($result,"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>";
echo "$myrow[id] $myrow[tradetype] $myrow[address] $myrowwuye[$myrow[date]]";
echo "</td>";
echo "详细内容</td>";
echo "</tr>";
}
}
else echo "<tr><td>


没有找到满足你条件的记录
& lt;/td></tr>";
}
$prev_page=$page-1;
$next_page=$page 1;
echo "
";
echo " 第".$page."/".$page_count."页&nbsp";
if ($page<=1){
echo "|第一页|";
}
else{
echo "|第一页|";
}
echo " ";
if ($prev_page<1){
echo "|上一页|";
}
else{
echo "|上一页|";
}
echo " ";
if ($next_page>$page_count){
echo "|下一页|";
}
else{
echo "|下一页|";
}
echo " ";
if ($page>=$page_count){
echo "|最后一页|";
}
else{
echo "|最后一页|";
}
echo "
";
}
else{
echo "

现在还没有房屋租赁信息!

";
}
echo "<hr width="100%" size="1">";
?>
</table>

猜你在找的PHP相关文章