I want to let the user sort the table base on what the user wants. I have two options for this, sort by name or sort by exam.
code
echo "<table border=1 align=center><tr class=style2><td><input type=radio name=sort value='byname'>Sort By Name<td><input type=radio name=sort value='byexam'>Sort By Exam";
$sort = $_POST['name'];
if ($sort == "byname"){
$sort=mysql_query("select * from mst_adminresult order by login ASC",$cn) or die(mysql_error());
while($row=mysql_fetch_row($sort))
echo "<table border=1 align=center><tr class=style2><td>Student Name <td> Test<br> Question <td> Score";
echo "<tr class=style8><td>$row[1] <td align=center> $row[2] <td align=center> $row[3]/20";
echo "</table>";
}else{
$sort=mysql_query("select * from mst_adminresult order by test_id ASC",$cn) or die(mysql_error());
while($row=mysql_fetch_row($sort))
echo "<table border=1 align=center><tr class=style2><td>Exam<td width=300>Student Name<td> Score";
echo "<tr class=style8><td>$row[1] <td align=center> $row[2] <td align=center> $row[3]/20";
echo "</table>";
}
echo "<table border=1 align=center><tr class=style2><td width=300>Student Name <td> Test<br> Question <td> Score";
while($row=mysql_fetch_row($rs))
{
echo "<tr class=style8><td>$row[1] <td align=center> $row[2] <td align=center> $row[3]/20";
}
echo "</table>";
the problem I am encountering is it doesn't function properly. The default arrangement of the data is listed by the latest exam taker to the last. Now what I am aiming for is, if the user checks the by the name option, it will sort by name. for the by exam, it will be listed by exam.

mysql_*functions are deprecated, they have been removed from PHP 7, your code will stop working when you upgrade to that version. You should not write new code using them, usemysqli_*or PDO instead.name="sort", yet you check$_POST['name']later. Change this to$_POST['sort'].