我有一个包含 3 个字段的搜索区域,一个是输入字段,另外两个是下拉菜单。有人在输入字段中输入内容,或者他们从两个下拉菜单(州和城市)中进行选择。
输入搜索工作正常。选择菜单没有。
这是表格。
<form name="ffl_finder" method="get" action="index.php">
Enter a Zip Code to find a Firearms Dealer near you: <br />
<input name="q" type="text" id="q" size="40">
Select a State AND a City<br />
<select name="qoption2">
<option value="" selected="selected">Select . . .</option>
<?php
$sql2 = "SELECT DISTINCT state from ffl_list order by state asc";
$rs_results2 = mysql_query($sql2) or die(mysql_error());
while ($rrows2 = mysql_fetch_array($rs_results2)) {
?>
<option value="<?php echo $rrows2[state]; ?>"><?php echo $rrows2[state]; ?></option>
<?php
}
?>
</select>
<select name="qoption3">
<option value="" selected="selected">Select . . .</option>
<?php
$sql3 = "SELECT DISTINCT city from ffl_list order by city asc";
$rs_results3 = mysql_query($sql3) or die(mysql_error());
while ($rrows3 = mysql_fetch_array($rs_results3)) {
?>
<option value="<?php echo $rrows3[city]; ?>"><?php echo $rrows3[city]; ?></option>
<?php
}
?>
</select>
<input name="doSearch" type="submit" id="doSearch" value="Search">
</form>
这是查询:
<?php if ($get['doSearch'] == 'Search') {
//$cond2 = '';
if($get['qoption2'] != '') {
$cond2 = "`state` = 'qoption2'";
}
//$cond3 = '';
if($get['qoption3'] != '') {
$cond3 = "`city` = 'qoption3'";
}
if($get['q'] == '') {
$sql = "select * from ffl_list where $cond2 and $cond3 order by state asc, city asc";
}
else {
$sql = "select * from ffl_list where `zip` = '$_REQUEST[q]' ORDER BY `id` asc";
}
$rs_results = mysql_query($sql) or die(mysql_error());
} ?>
我需要查询来搜索城市和州,但我似乎无法获得正确的条件。我知道这是很多代码,但是如果有人可以提供帮助,那就太好了。
谢谢,
克林特