我有两张表add_projects
和floor_plan
。在第二个表project_id
很常见。在成功选择add_projects
表格(此处我将获得project_id
)的结果后,我想查看floor_table WHERE project_id='$project_id'
的最低价格。我正在尝试如下,但我没有得到最小值。我该怎么做?
<?php
include("admin/dbconfig.php");
include("admin/functions.php");
$property = $_POST['property']; // official shadow - 3
$min_price = $_POST['min_price']; // 5-10
$min_explode = explode("-",$min_price);
$min1 = $min_explode[0]; // 5
$min2 = $min_explode[1]; // 10
/* $min1 = 5;
$min2 = 10 */;
$max_price = $_POST['max_price'];// 35-40
$max_explode = explode("-",$max_price);
$max1 = $max_explode[0] ; // 35
$max2 = $max_explode[1] ; // 40
/*$max1 = 20;
$max2 = 40; */
$location = $_POST['location'];
$query = "SELECT * FROM add_projects WHERE property='$property' AND property_type='3'";
if ($min_price!='') {
$query.=" AND total_price BETWEEN $min1 AND $min2";
//SELECT * FROM add_projects1 WHERE property='3' AND total_price BETWEEN 5 AND 10 (2 rows)
}
if ($max_price!='') {
$query .= " OR (total_price BETWEEN $max1 AND $max2)";
//SELECT * FROM add_projects1 WHERE property='3' AND total_price BETWEEN 5 AND 10 OR (total_price BETWEEN 10 AND 15) 3 rows
}
if ($location!=''){
$query .= " AND (project_location='$location')";
}
$sql = mysql_query($query);
/* while($rlt=mysql_fetch_assoc ($sql)) {
$row= $rlt['project_title'].'//';
}*/
$count = mysql_num_rows($sql);
if ($count > 0) {
while ($row=mysql_fetch_assoc($sql)) {
$project_id = $row['project_id'];
$row['project_location'] = Get_project_location($row['project_location']);
$row['property'] = Get_property($row['property']);
/* Here I want to get min price of floor_plan table condition project_id = "$project_id"
$min = mysql_query("SELECT id,price FROM floor_plan WHERE project_id='2' order by price ASC LIMIT 1 ");
while($mp=mysql_fetch_assoc($min)){
$row['floor_min'] =$mp["price"];
}*/
$data[] = $row;
}
$buy_type = array("status"=>1,"count" =>$count,"data" =>$data);
echo $buy_type = json_encode($buy_type);
} else {
$buy_type = array("status"=>0,"count" =>0,"data" =>"");
echo $buy_type = json_encode($buy_type);
}
?>