PHP - 通过下拉菜单运行两个使用“SELECT”的Mysql查询

时间:2012-12-01 00:15:21

标签: php mysql select drop-down-menu

基本上,我有一个下拉菜单,有两个选项 - “全部”和“ '评分最高'。

<select class="dropdown">
<option value="all">All</option>
<option> value="toprated">Top Rated</option>
</select>

我想通过“全部”选项...

运行此查询
$myQuery  = "SELECT Attraction.*, Type.TypeName, Rating.RatingUrl ";
$myQuery .= "FROM Attraction ";
$myQuery .= "INNER JOIN Type ON Attraction.Type = Type.TypeID ";
$myQuery .= "INNER JOIN Rating ON Attraction.AttractionID = Rating.AttractionID ";
$myQuery .= "WHERE Attraction.Type = 4 ";
$myQuery .= "ORDER BY Name ";

$result = mysql_query($myQuery);
if (!$result) {
    die('Query error: ' . mysql_error());
}

此查询通过“评分最高”选项......

$myQuery  = "SELECT Attraction.*, Type.TypeName, Rating.RatingUrl ";
$myQuery .= "FROM Attraction ";
$myQuery .= "INNER JOIN Type ON Attraction.Type = Type.TypeID ";
$myQuery .= "INNER JOIN Rating ON Attraction.AttractionID = Rating.AttractionID ";
$myQuery .= "ORDER BY Rating DESC, Name ";

$result = mysql_query($myQuery);
if (!$result) {
    die('Query error: ' . mysql_error());
}

任何人都可以生成我需要的PHP结构...

如果有人能提供帮助那就太棒了!

1 个答案:

答案 0 :(得分:0)

我建议使用此tutorial for PHP和此mysqli阅读

另外,检查WebChemist所说的内容:

不行:

<option> value="toprated">Top Rated</option>

确定:

<option value="toprated">Top Rated</option>