我正在做一个 sch 项目,我需要通过单击标题行按字母顺序对数据表进行排序的帮助。我正在使用 MySQL,我打算使用 php 来实现它。谁能帮我?谢谢。
这是我的代码:
这是一个 php 文件。
<?php
@ $db = new mysqli('localhost', 'f33s01', 'f33s01', 'f33s01');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from gyms";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<table border=\"3\" cellpadding=\"5\" class=\"dirtable\" style=\"margin-bottom:15px\">
<tr align=\"center\" class=\"gold\">
<th>Number</th>
<th>Gym Name</th>
<th>Address</th>
<th>Location</th>
<th width=\"18%\">Operating Hours</th>
<th>Reservation</th>
</tr>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<tr>";
echo "<td align=\"center\">".($i+1)."</td>";
echo "<td align=\"center\">".stripslashes($row['gymname'])."</td>";
echo "<td>".stripslashes($row['address'])."</td>";
echo "<td>".stripslashes($row['location'])."</td>";
echo "<td align=\"center\">".stripslashes($row['operatinghours'])."</td>";
echo "<td align=\"center\"><input type= \"submit\" value=\"BOOK NOW\" class=\"bookbutton\"></td>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
$result->free();
$db->close();
?>