我只是想問一下,如果我可以按字母順序排列回聲記錄,有可能嗎?例如,我想根據他們姓名的首字母按字母順序排列記錄。我也必須添加一些東西來發生?或者甚至有可能?按字母順序排列PHP中的記錄
我知道如何按字母順序排列HTML中的所有內容,我不確定它是否像PHP一樣工作。
這裏是我的PHP代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
\t body {
\t \t background-image: url("img/wood3.jpg");
\t }
\t html *
\t {
\t margin: auto;
\t color: #000 !important;
\t font-family: Questrial !important;
\t }
</style>
\t <link href="https://fonts.googleapis.com/css?family=Questrial" rel="stylesheet">
\t <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
\t
<title>CORE INTRANET</title>
</head>
<body>
<br>
<center><h1> View Records </h1></center>
<center><a href="home.php"><img src="img/homebutton.png" height="35" width="35"></a></center>
<br>
<?php
// connect to the database
include('connect-db.php');
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM signup_and_login_users_table ORDER BY id"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>ID</th><th>Full Name</th><th>Username</th><th>Email</th><th>Address</th><th>Contact</th><th>Gender</th><th>Password</th><th>Access Level</th><th>Date</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
\t echo "<tr>";
\t echo "<td>" . $row->id . "</td>";
\t echo "<td>" . $row->name . "</td>";
\t echo "<td>" . $row->username . "</td>";
\t echo "<td>" . $row->email . "</td>";
\t echo "<td>" . $row->address . "</td>";
\t echo "<td>" . $row->contact . "</td>";
\t echo "<td>" . $row->gender . "</td>";
\t echo "<td>" . $row->password . "</td>";
\t echo "<td>" . $row->user_levels . "</td>";
\t echo "<td>" . $row->date . "</td>";
\t echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
\t echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
\t echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
?>
</body>
</html>
我剛剛注意到,我如此愚蠢。謝謝 –
如果解決了您的問題,請接受答案。 – OptimusCrime
我會但我還要等10分鐘。 –