我希望能够通过单击标题对表格进行排序。我在网上找到了一些如何做到这一点的例子,但是当我尝试遵循它们时,我得到了错误。任何帮助将不胜感激。这是我用来从 MySQL 创建表的 PHP 代码。
<?php
session_start();
$Town = $_POST['Town'];
$Range = $_POST['Range'];
$Section = $_POST['Section'];
$con = mysql_connect('server, 'database', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ncwrpc", $con);
$sql = "SELECT * FROM `index8` WHERE `MAPID` = $Town$Range$Section LIMIT 0, 500 ";
$result = mysql_query($sql);
echo "<table border='2' cellpadding='5' cellspacing='2' bordercolor='#000000' bgcolor='#B8B8B8' >
<tr>
<h2>TOWN: $Town N - RANGE: $Range E - SECTION: $Section</h2>
<th bgcolor=\"#669999\">MAP</th>
<th bgcolor=\"#669999\">DESC. 1</th>
<th bgcolor=\"#669999\">DESC. 2</th>
<th bgcolor=\"#669999\">REMARKS</th>
<th bgcolor=\"#669999\">SURVEYOR</th>
<th bgcolor=\"#669999\">CLIENT</th>
<th bgcolor=\"#669999\">YEAR</th>
</tr>";
$color = "0";
while($row = mysql_fetch_array($result))
{
if($color == "0"){
echo "<tr>";
echo "<td bgcolor=\"#FFFFFF\"><a href=\"".$row['LINK']."\" target=\"_blank\">".$row['MAP1']."</a></td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Desc1'] . "</td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Desc2'] . "</td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Remarks'] . "</td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Surveyor'] . "</td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Client'] . "</td>";
echo "<td bgcolor=\"#FFFFFF\">" . $row['Y'] . "</td>";
echo "</tr>";
$color = "1";
}else{
echo "<tr>";
echo "<td bgcolor=\"#FFF380\"><a href=\"".$row['LINK']."\" target=\"_blank\">".$row['MAP1']."</a></td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Desc1'] . "</td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Desc2'] . "</td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Remarks'] . "</td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Surveyor'] . "</td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Client'] . "</td>";
echo "<td bgcolor=\"#FFF380\">" . $row['Y'] . "</td>";
echo "</tr>";
$color = "0";
}
}
?>