我有一個顯示MYSQL數據庫信息的頁面。PHP通過表單排序
我由具有排序選項
表格形式
<form action= "properties.php" method="post" name="SortingForm">
<label for="SortBy">Sort by</label>
<select name="SortBy">
<option value="Added">Date Added</option>
<option value="Location">Location</option>
<option value="Type">Type</option>
<option value="Price">Price</option>
</select>
<input type="radio" name="SortingOrder" value="Ascending" checked> Ascending
<input type="radio" name="SortingOrder" value="Descending"> Descending<br>
</form>
這是PHP如何默認顯示的信息
輸出
<?php
require("connect.php");
//Linking
$link = connectToDB();
//SQL Query
$sql = "SELECT tbl_property.propertyid,tbl_property.imagename,tbl_property.locationid,tbl_property.typeid,tbl_property.price,
tbl_town.townname,
tbl_type.typename
FROM tbl_property,tbl_town,tbl_type
WHERE tbl_town.townid = tbl_property.locationid AND tbl_type.typeid = tbl_property.typeid";
//Execute
$result = $link->query($sql);
//Table Start
echo "<table class='table'>";
echo "<tr>";
echo "<th>Picture</th>";
echo "<th>Location</th>";
echo "<th>Type</th>";
echo "<th>Price</th>";
echo "<th>More Information</th>";
if(isset($_SESSION['id'])){
echo "<th>Edit Property</th>";
echo "<th>Delete Property</th>";
}
echo "</tr>";
while ($row = $result->fetch_assoc()) {
//Image Name
$ImageGetter = "images/".$row['imagename'];
//Information
echo "<tr>";
echo '<td><img height="150" width="200"" src="'.$ImageGetter.'" /></td>';
echo "<td>".$row['townname']."</td>";
echo "<td>".$row['typename']."</td>";
echo "<td>€".$row['price']."</td>";
echo "<td>"."<a href=\"profile.php?id=".$row['propertyid']."\"> <button type='button' class='btn btn-default'>More Info</button></a>"."</td>";
//If user is logged in, give extra buttons
if(isset($_SESSION['id'])){
echo "<td>"."<button type='button' class='btn btn-info'>Edit</button>"."</td>";
echo "<td>"."<a href=\"delete.php?id=".$row['propertyid']."\"> <button type='button' class='btn btn-danger'>Delete</button></a>"."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
我的問題是,這將有可能使從從形式選擇的排序選項數據庫更改顯示的信息,如果是這樣,怎麼樣?因爲我無法弄清楚。請記住,展示確實有效,頁面上的所有內容都可以正確顯示,但按照最早到最新排序。
你有沒有試過用你的'