0

我有一个表格试图搜索不同的价格。我设法搜索地址和城市信息,但没有显示搜索结果的价格。我不确定它是在 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=""/>';
    }

?>

谢谢

4

1 回答 1

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'");
于 2013-05-19T04:58:59.610 回答