2015-09-04 192 views
-1
SELECT * FROM table name 
where property_type='residential' and lp_dol BETWEEN '1' and '450000' 
and cross_st='city name' 

我想搜索屬性值,如1至450,000之間的價格在像任何城市名稱的城市。MySQL查詢返回不正確的結果

但現在表示的範圍(1 - 450000)的值與上述價格範圍等價格-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"; 
} 

    ?> 
+1

請編輯您的問題並添加表格定義,如'SHOW CREATE TABLE'所示。 – VolkerK

+0

加上關於php和mysql的示例數據和版本信息。 – VolkerK

+0

請稍候我在這裏更新我的php代碼... – avktech

回答

0

如果lp_dol是INTEGER數據類型的你需要排除單引號

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

不知道爲什麼這是投票 – Strawberry

+0

他們不檢查只是看到其他投票和其他人做同樣的。因爲我100%肯定以上我的代碼工作100% –

-1

請使用

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

我希望這肯定會爲你工作,因爲你需要價值之間,那麼它也爲你工作。

+0

這個答案在功能上與原來的一樣,並遭受同樣的缺陷 – Strawberry

+0

我的親愛的朋友你的代碼不工作.... – avktech

+0

我可以問你的價值在integar或者上面的代碼檢查小於或者大於那麼正在處理整數值。請檢查您的價值和使用後。 –