ヘッダーをクリックしてテーブルをソートできるようにしたい。これを行う方法の例をオンラインでいくつか見つけましたが、それらに従おうとするとエラーが発生します。どんな助けでも大歓迎です。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";
}
}
?>