我是 php 新手,我遇到了问题。
我有三个下拉菜单来对结果进行排序,但我想这样做,所以如果他们不选择任何内容,则默认值为 SELECT * FROM 餐厅,并且如果只选择一个下拉菜单以仅考虑该字段。
<form id="form" name="vicinity" method="post" action="restaurant-list.php">
<select class="form-banner" size="1" id="vicinity" name="vicinity">
<option value=""> Select one </option>
<option value="Back Bay">Back Bay</option>
<option value="Beacon Hill">Beacon Hill</option>
<option value="Chinatown">Chinatown</option>
</select><br><br>
<p class="font-2">Search by Cuisines</p>
<select class="form-banner" size="1" id="cuisine" name="cuisine">
<option value=""> Select one </option>
<option value="American">American</option>
<option value="Chinese">Chinese</option>
<option value="Indian">Indian</option>
</select><br><br>
<p class="font-2">Search by Price</p>
<select class="form-banner" size="1" id="price" name="price">
<option value=""> Select one </option>
<option value="$">$ - Cheap</option>
<option value="$$">$$ - Moderate</option>
<option value="$$$">$$$ - Pricey</option>
</select><br><br>
<input type="submit" id="banner-search" value="Search"/>
</form>
餐厅页面(目前仅在选择所有字段时有效)如果留空,则不显示任何内容。
<?php
require ("db.php");
$vicinity = $_POST["vicinity"];
$cuisine = $_POST["cuisine"];
$price = $_POST["price"];
$query = "SELECT * FROM restaurant WHERE vicinity=\"$vicinity\" AND cuisine=\"$cuisine\" AND price=\"$price\"";
$result = mysql_query($query);
?>
任何帮助或想法如何实现这一点。