我有一个选择菜单,可以选择如何对数据库中的数据进行排序。我坚持不知道如何根据日期和考试对其进行排序。
到目前为止,这是我的代码:
echo "<form action=results.php method=post>";
echo "Sort By: <select name=q><option value= name=></option><option value=date name=date>Date</option><option value=exam name=exam>Exam</option></select>";
echo "</form>";
if()
$q = $_GET['q'];
echo "<table border=1 align=center><tr class=style2><td>Date <td>Student Name <td> Subject <td> Score";
$sortQuery = mysql_query("SELECT * FROM mst_adminresult m
JOIN mst_test t ON t.test_id = m.test_id
JOIN mst_subject s ON s.sub_id = t.sub_id order by'".$q."'" ,$cn) or die(mysql_error());
while($row=mysql_fetch_row($sortQuery))
{
echo "<tr class=style8><td>$row[5]<td>$row[1] <td align=center> $row[4] <td align=center> $row[3]/20";
}
echo "</table>";
答案 0 :(得分:1)
&#34;&#34;&#34;必须有空间!
样品:
... ORDER BY column_name ASC|DESC ...
答案 1 :(得分:0)
这是你修改过的代码,让我焦虑地看到它:
echo '<form action="results.php" method="post">';
echo 'Sort By: <select name="q"><option value=""></option><option value="date">Date</option><option value="exam">Exam</option></select>';
echo '</form>';
if(isset($_GET['q']) {
$q = $_GET['q'];
} else {
$q = 'date';
}
echo '<table border="1" align="center"><tr class="style2"><td>Date</td><td>Student Name</td><td>Subject</td><td>Score</td></tr>';
$sortQuery = mysql_query("SELECT * FROM mst_adminresult
JOIN mst_test t ON t.test_id = m.test_id
JOIN mst_subject s ON s.sub_id = t.sub_id order by `".$q."`" ,$cn) or die(mysql_error());
while($row=mysql_fetch_row($sortQuery))
{
echo '<tr class="style8"><td>$row[5]</td><td>$row[1]</td><td align=center>$row[4]</td><td align=center>$row[3]/20</td></tr>';
}
echo '</table>';
一些观察结果:
'this "text"'
或"this \"text\""
我希望它有所帮助。