我有一个搜索表单,我有 4 个表单域
- 财产
- 最低价格
- 最高价格
- 地点
此处属性字段仅是强制性的,其余 3 个字段是可选的,现在我将告诉我的要求用户仅选择属性意味着我想显示详细信息(从 db 获取匹配的记录)。假设用户选择属性和最低价格意味着我想显示(从数据库中获取匹配记录)的详细信息,其余两个文件相同,我正在尝试这样但我无法获取,请参阅此处我的数据库结构单击此处
$(document).ready(function(){
$('#buy_btn').click(function(){
if($('#buyForm').valid()){
$.ajax({
type:'POST',
url :"select_buy_properties.php",
data: $('form#buyForm').serialize(),
success: function(data) {
console.log(data);
},
error:function(exception){
alert('Exeption:'+exception);
}
});
return false;
}
});
});
<form id="buyForm" method="POST">
<div class="col-md-11 col-sm-11 col-xs-11" >
<div class="search1">
<div class="col-md-2 col-sm-3 col-xs-3" style="padding-left:0px;padding-right: 2px;">
<!---->
<select class="ui search dropdown" style=" width: 100%; height: 45px;padding-left:10px;font-size: 17px !important; font-family: inherit;" data-msg-required="Select Propery" required="" aria-required="true" name="property">
<option value="">Property</option>
<?php
$p = mysql_query("SELECT * FROM properties WHERE status !='1'");
while($pp = mysql_fetch_assoc($p))
{
echo '<option value="'.$pp["id"].'">'.$pp["properties"].'</option>';
}
?>
</select>
<!---->
</div>
<div class="col-md-2 col-sm-3 col-xs-3" style="padding-left:0px;padding-right: 2px;">
<!---->
<select class="ui search dropdown" style=" width: 100%; height: 45px;padding-left:10px;font-size: 17px !important; font-family: inherit;" name="min_price">
<option value="">Min Price</option>
<option value="500000-1000000">5-10 Lacs</option>
<option value="1000000-2000000">10-20 Lacs</option>
<option value="2000000-3000000">20-30 Lacs</option>
<option value="3000000-4000000">30-40 Lacs</option>
<option value="4000000-5000000">40-50 Lacs</option>
<option value="5000000-6000000">50-60 Lacs</option>
<option value="6000000-7000000">60-70 Lacs</option>
<option value="7000000-8000000">70-80 Lacs</option>
<option value="8000000-9000000">80-90 Lacs</option>
<option value="10000000-100000000">100+ Lacs</option>
</select>
<!---->
</div>
<div class="col-md-2 col-sm-3 col-xs-3" style="padding-left:0px;padding-right: 2px;">
<!---->
<select class="ui search dropdown" style=" width: 100%; height: 45px;padding-left:10px;font-size: 17px !important; font-family: inherit;" name="max_price">
<option value="">Max Price</option>
<option value="1000000-2000000">10-20 Lacs</option>
<option value="2000000-3000000">20-30 Lacs</option>
<option value="3000000-4000000">30-40 Lacs</option>
<option value="4000000-5000000">40-50 Lacs</option>
<option value="5000000-6000000">50-60 Lacs</option>
<option value="6000000-7000000">60-70 Lacs</option>
<option value="7000000-8000000">70-80 Lacs</option>
<option value="8000000-9000000">80-90 Lacs</option>
<option value="10000000-100000000">100+ Lacs</option>
</select>
<!---->
</div>
<div class="col-md-4 col-sm-4 col-xs-4" style="padding-left:0px;padding-right: 2px;">
<!---->
<select class="ui search dropdown" style=" width: 100%; height: 45px;padding-left:10px;font-size: 17px !important; font-family: inherit;" name="location">
<option value="">Location</option>
<?php
$l = mysql_query("SELECT * FROM location WHERE status !='1'");
while($ll = mysql_fetch_assoc($l))
{
echo '<option value="'.$ll["id"].'">'.$ll["location"].'</option>';
}
?>
</select>
<!---->
</div>
<div class="col-md-2 col-sm-2 col-xs-2" style="padding-left:0px;padding-right: 2px; !important;padding-right:0px !important;">
<button type="button" class="btn btn-primary btn-lg" style="background-color: #e85700 !important;
border-color: #e85700 !important; font-size: 14px !important;height: 44px; width:100%; padding-left:11px; " id="buy_btn">SEARCH<!--<span class="glyphicon glyphicon-search" aria-hidden="true"></span>--></button>
</div>
</div>
</div>
</form>
select_buy_properties.php
include("admin/dbconfig.php");
$property = $_POST['property'];
$min_price = $_POST['min_price'];//5000000-1000000
$min_explode = explode("-",$min_price);
$min1= $min_explode[0] ; //5000000 5 lacs
$min2= $min_explode[1] ; //1000000 10 lacs
$max_price = $_POST['max_price'];
$max_explode = explode("-",$min_price);
$max1= $max_explode[0] ; //10,00,000 ten lacs
$max2= $max_explode[1] ; //20,00,000 twenty lacs
$location = $_POST['location'];
$query="SELECT * FROM add_projects WHERE property ='$property' AND status!=''";
if($min_price!='')
{
$query.="AND ( total_price BETWEEN '600000' AND '700000')";
}
if($max_price!='')
{
$query.="AND ( total_price BETWEEN '700000' AND '1000000')";
}
if($location!='')
{
$query.=" AND project_location='$location'";
}
$sql=mysql_query($query);
while($rlt=mysql_fetch_assoc($sql)){
echo $rlt['project_title'];
}