How can the PHP code be modified to display all news entries in descending order based on the ID?

To display all news entries in descending order based on the ID, we can modify the SQL query in the PHP code to include an ORDER BY clause with the ID column in descending order. This will ensure that the news entries are displayed from the highest ID to the lowest ID.

<?php
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "news_database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Select all news entries in descending order based on ID
$sql = "SELECT * FROM news_entries ORDER BY id DESC";
$result = $conn->query($sql);

// Display news entries
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"]. " - Title: " . $row["title"]. " - Content: " . $row["content"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>