MySQL查询返回不正确的结果

时间:2015-09-04 07:27:47

标签: php mysql

SELECT * FROM table name  
where property_type='residential' and lp_dol BETWEEN '1' and '450000' 
and cross_st='city name'

我希望像任何城市名称一样在城市中搜索1到450,000之间的房产价值。

但现在显示范围内的值(1 - 450,000),某些结果高于价格范围,如价格-1000390,(某些结果并非全部

 <?php  $mydata = array();
  if($protype_se!="" && $protype_se!="0") {
  $mydata[] = "property_type='$protype_se'";
 }
 if($protype_city !="") {
  $mydata[] = "cross_st='$protype_city'";
}
if($protype_from !="" && $protype_to !="") {
  $mydata[] = "lp_dol BETWEEN $protype_from and $protype_to";
}elseif($protype_from =="" && $protype_to !=""){
    $mydata[] = "lp_dol BETWEEN $protype_cust and $protype_to";
}
if($protype_bed !="") {
  $mydata[] = "br >='$protype_bed'";
}if($protype_baths !="") {
  $mydata[] = "bath_tot >='$protype_baths'";
}

if($protype_pstyle !=""&& $protype_pstyle !="Att/Row/Twnhouse") {
  $mydata[] = "style='$protype_pstyle'";
}elseif($protype_pstyle !="" && $protype_pstyle =="Att/Row/Twnhouse" ){

    $mydata[] = "town='$protype_pstyle'";
}
if($protype_gtype !="") {
  $mydata[] = "gar_type='$protype_gtype'";
}
if($protype_pool !="") {
  $mydata[] = "pool='$protype_pool'";
}
if($protype_fplace !="") {
  $mydata[] = "fpl_num='$protype_fplace'";
}
if($protype_for !="") {
  $mydata[] = "s_r='$protype_for'";
}
if($protype_gmin!="" && $protype_gmax!="") {
  $mydata[] = "gross_texes BETWEEN '$protype_gmin' and '$protype_gmax'";
}
if($protype_lmin!="" && $protype_lmax!="") {
  $mydata[] = "land_size BETWEEN '$protype_lmin' and '$protype_lmax'";
}
if($protype_pmin!="" && $protype_pmax!="") {
  $mydata[] = "price_sqft BETWEEN '$protype_pmin' and '$protype_pmax'";
}if($protype_se!="" && $protype_se=="0") {
  $mydata[] = "lp_dol BETWEEN '$protype_cust' and '$protype_end'";
 }
      $quer = "SELECT * FROM listing_featured_property";
 $sql = $quer;
  if (count($mydata) > 0) {
    $sql .= " where " . implode(' and ', $mydata)." order by lp_dol DESC   LIMIT $offset, $limit";
} 

   ?>

2 个答案:

答案 0 :(得分:0)

如果lp_dol是INTEGER数据类型,则需要排除单引号

SELECT * FROM table name  
where property_type='residential' and lp_dol BETWEEN 1 and 450000 and cross_st='city name'

答案 1 :(得分:-1)

请使用此

SELECT * FROM table name  where property_type='residential' and (lp_dol>= '1' and lp_dol<='450000') and cross_st='city name'

我希望这对你有用,因为你需要价值,因为它也适合你。