Order by DESC
Can anyone please tell me why the following code will not output the data in DESC order and how the code can be fixed?
<?php
$conn = mysqli_connect("localhost", "root", "", "DATABASE");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM TABLE ORDER BY id DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" .
$row["id"].
"</td><td>".
$row["datetime"].
"</td><td>".
$row["name"].
"</td><td>".
$row["company"].
"</td><td>".
$row["mobile"].
"</td><td>".
$row["permit"].
"</td><td>".
$row["pass"].
"</td><td>".
$row["location"].
"</td><td>".
$row["ep"].
"</td><td>".
$row["reg"].
"</td><td>".
$row["comments"].
"</td></tr>";
}
echo "</table>";
} else { echo "0 results"; }
$conn->close();
?>
Subject
Written By
Posted
Order by DESC
May 03, 2019 08:05AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.