我有一个具有唯一 ID 的 mysql 表,我将它们显示在一个 html 表中。对于那些好奇的人,这里是代码。
<?php
require_once '../page.php';
require 'checklogin.php';
$page = new Page();
$page->title = 'View Students';
$page->sidebarliab = true;
$lastvari;
$id = $_GET['id'];
echo $id;
// Connect to database
$con = new mysqli($mysqlurl, $mysqlusername, $mysqlpassword, $mysqldatabase);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Prepare to select all students
$stmt = $con->prepare("SELECT Last_Name, First_Name, Student_ID FROM Students LIMIT 30");
$stmt->execute(); // Execute the query
$stmt->bind_result($last_name, $first_name, $student_id); // Bind variables to the result of the query
?>
<h2 style='margin-left:1%'>All Students</h2>
<table id='liabilityTable'>
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Student ID</th>
<th>Homeroom</th>
<th>Number of Liabilities</th>
</tr>
</thead>
<tbody>
<?php
while($stmt->fetch()) {
echo "<tr>";
?>
<td><?=$last_name?></td>
<td><?=$first_name?></td>
<td><?=$student_id?></td>
<?php
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
$lastvari = $student_id;
}
$stmt->close(); // Close the statement
$con->close(); // Close connection to database
?>
</tbody>
</table>
<a href=<?php echo "students_view.php?id=$lastvari"; ?>><button type="button">Next Page</button></a>
所以基本上,这是一张桌子。我希望能够单击第一行并能够按字母顺序组织它(比如单击姓氏将按姓氏组织,单击 ID 将按数字排列,等等,就像在 Windows 资源管理器中一样)。有谁知道我怎么能做到这一点?无论是解决方案还是仅仅指向正确的方向都绝对很棒。