我希望能夠通過點擊標題來排序表。我在網上找到了一些關於如何做到這一點的例子,但是當我嘗試關注它們時,我得到了錯誤。任何幫助將不勝感激。這裏是我用來從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";
}
}
?>
當你寫「我有錯誤「,你應該說他們在哪裏以及哪些錯誤。不要說「第5行」,因爲我們不知道哪一行是行號。 5. – Voitcus 2013-03-24 13:52:31
這裏缺少一個撇號'$ con = mysql_connect('server,'database','password');' – Voitcus 2013-03-24 13:53:25
上面沒有任何錯誤可以正常工作。只是想添加排序。是的,上面提到的mysql _connect存在錯誤,我只是從這篇文章中刪除了服務器名稱等。我將按照下面的建議查看jquery。 – user2204589 2013-03-24 17:21:49