我是MySQL和PHP的新手。我正在建立一个显示MySQL结果的网站,然后有一个选择选项,允许观众选择他希望如何排序结果,然后他被带到另一个页面并排序结果。
这是我的select函数代码:
<div id="query">
<label style="font-weight:bold;display:inline;">Sort By:</label>
<select id="selection">
<option value="">Choose to sort...</option>
<option value="?sort=ranking">Ranking</option>
<option value="?sort=price_asc">Price: Low to high</option>
<option value="?sort=price_desc">Price: High to low</option>
<option value="?sort=title_asc">Title: A to Z</option>
<option value="?sort=title_desc">Title: Z to A</option>
</select>
<script>
document.getElementById("selection").onchange = function() {
if (this.selectedIndex!==0) {
window.location.href = this.value;
}
};
</script>
</div>
以下是更改查询的代码:
$Query = "SELECT * FROM `AhopData` WHERE `Item` = 999";
“出于某种原因,这是行不通的。任何帮助都会非常感激。谢谢”
答案 0 :(得分:1)
在ORDER BY子句
之后尝试使用LIMIT$Query = "SELECT * FROM `GamesData` WHERE `Ranking` <=20";
if ($_GET['sort'] == 'ranking')
{
$Query .= " ORDER BY Ranking ASC";
}
elseif ($_GET['sort'] == 'price_asc')
{
$Query .= " ORDER BY Price ASC";
}
elseif ($_GET['sort'] == 'price_desc')
{
$Query .= " ORDER BY Price DESC";
}
elseif($_GET['sort'] == 'title_asc')
{
$Query .= " ORDER BY Title ASC";
}
elseif($_GET['sort'] == 'title_desc')
{
$Query .= " ORDER BY Title DESC";
}
$Query .= " LIMIT $limit";