搜索价格表格

时间:2013-05-19 04:55:26

标签: php mysql search

我有一张试图搜索不同价格的表单。我设法搜索地址和城市信息,但价格没有显示搜索结果。我不确定它是在HTML方面还是PHP方面我出错了。我正在使用2个下拉列表,其中包含一定数量的价格范围。

HTML

<select name="PriceMin">
                <option value="min(900)">900</option>   
                <option value="min(1000)">1000</option>
                <option value="min(2000)">2000</option>   
                <option value="min(3000)">3000</option>  
                <option value="min(4000)">4000</option> 
                <option value="min(5000)">5000</option> 
                <option value="min(6000)">6000</option> 
                <option value="min(7000)">7000</option>   
                <option value="min(8000)">8000</option>           
            </select>

            <select name="PriceMax">
                <option value="min(1000)">1000</option> 
                <option value="min(2000)">2000</option>
                <option value="min(3000)">3000</option>   
                <option value="min(4000)">4000</option>  
                <option value="min(5000)">5000</option> 
                <option value="min(6000)">6000</option> 
                <option value="min(7000)">7000</option> 
                <option value="min(8000)">8000</option>   
                <option value="min(9000)">9000</option>           
            </select>

PHP

<?php
////////////connect with database goes here////////


///////////set search variables
$property = $_POST['property'];
$bedroom = $_POST['BedroomNumber'];
$bathroom = $_POST['BathroomNumber'];
$priceMin = $_POST['PriceMin'];
$priceMax = $_POST['PriceMax'];

//////////search
$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '%priceMin%' and '%priceMax%'");

if($sql === FALSE) {
    die(mysql_error()); // TODO: better error handling
}

/////////display search results
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
    echo 'ID: '.$row['Property'];
    echo '<br/> Address: '.$row['StreetAddress'];
    echo '<br/> City: '.$row['City'];
    echo '<br/> Phone: '.$row['Phone'];
    echo '<br/> Bedroom: '.$row['NumBed'];
    echo '<br/> Bathroom: '.$row['NumBath'];
    echo '<br/><img src="images/'.$row['imageName1'].'" width="200" height="150" alt=""/>';
    }

?>

由于

1 个答案:

答案 0 :(得分:1)

更改: -

$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '%priceMin%' and '%priceMax%'");

$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '$priceMin' and '$priceMax'");