我有一個使用JOIN連接在一起的表格,我想創建一個帶有提交按鈕的表單,允許最終用戶更改他們希望過濾表格的方式。 排序欄在我的網頁上,但它實際上沒有做任何事情。所以我的問題是我需要做什麼才能讓排序按鈕起作用。使用PHP對下拉表中的SQL查詢進行排序
<?php
$sort = @$_POST['order'];
if (($sort)) { // If you Sort it with value of your select options
$query = "SELECT n.firstname, n.middlename, n.lastname, m.title, f.format, t.price, e.series, t.inventory
FROM book_main AS m
JOIN book_author AS n ON n.author_id=m.author_id
JOIN book_title AS t ON t.title_id=m.title_id
JOIN book_format AS f ON f.format_id=m.format_id
LEFT JOIN book_series AS e ON e.series_id=m.series_id
ORDER BY '".$sort."' ASC";
}
else { // else if you do not pass any value from select option will return this
$query = "SELECT n.firstname, n.middlename, n.lastname, m.title, f.format, t.price, e.series, t.inventory
FROM book_main AS m
JOIN book_author AS n ON n.author_id=m.author_id
JOIN book_title AS t ON t.title_id=m.title_id
JOIN book_format AS f ON f.format_id=m.format_id
LEFT JOIN book_series AS e ON e.series_id=m.series_id
ORDER BY n.lastname ASC";
$results = mysql_query($query);
echo $results['order'];
//can I have a couple points for trying so hard haha...
}
?>
<form name="sort" action="" method="post">
<select name="order">
<option value="choose">Make A Selection</option>
<option value='lastname'>Authors Last name</option>
<option value='price'>Price</option>
<option value='inventory'>Inventory</option>
</select>
<input type="submit" value="Sort" />
</form>
問一個問題吧。 –
同意。您是否要求我們提交提交按鈕? – NickSentowski
是的,我要求提交按鈕的工作。因爲它目前沒有做任何事 –