我有一个使用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
是的,我要求提交按钮的工作。因为它目前没有做任何事 –