【发布时间】:2011-07-22 20:23:02
【问题描述】:
当我正在拔头发时,我真的需要一些帮助!!! 我有两个字段,一个是输入框,另一个是下拉列表,用于搜索数据库并显示结果,但我似乎无法弄清楚......这是我到目前为止所拥有的......
这是实际的搜索表单:
<form id="myform" name="myform" action="<?php echo $_SERVER['PHP_SELF']?>" method="get"><br />
<div class="T1"><br /><p></div> <input name="term" type="text" value="<? php echo $_GET['searched']; ?>" size="10" maxlength="4" placeholder="e.g. BS1"/>
<select>
<option value="">I feel like...</option>
<option value="">Anything</option>
<option value="Indian">Indian</option>
<option value="Chinese">Chinese</option>
<option value="Thai">Thai</option>
</select>
<input type="submit" name="submit" value="Go"/>
</form>
这是 PHP 代码:
<?php
if (isset($_GET['submit'])){
mysql_connect ("host", "user","password") or die (mysql_error());
mysql_select_db ("database");
$term = $_GET['term'];
$term = $_GET['option value'];
}
else
$sql = mysql_query("select pagetitle from Restaurant where extra like '%$term%' and showing like '1'");
$sql = mysql_query("select cuisine from Restaurant where cuisine like 'option value' and showing like '1'");
echo Restaurants in $term and Cuisine $option value:";
}
while ($row = @mysql_fetch_array($sql)){
echo ''.$row['pagetitle'];
echo '<br/>';
}
}
?>
数据库有一个名为 Restaurant 的表,其中包含两个列,一个名为“Extra”,其中包含邮政编码,另一个名为“Cuisine”,其中包含美食。 我希望它返回与“Extra”和“Cuisine”匹配的餐厅列表 任何帮助将不胜感激。
【问题讨论】:
标签: php mysql database search webforms