What are some best practices for organizing and displaying news entries by date in a PHP script?

When organizing and displaying news entries by date in a PHP script, it is best practice to retrieve the news entries from a database in descending order by date, and then loop through the results to display them in the desired format. This ensures that the newest entries are displayed first and that the entries are organized chronologically.

// Retrieve news entries from the database in descending order by date
$query = "SELECT * FROM news_entries ORDER BY date DESC";
$result = mysqli_query($connection, $query);

// Loop through the results and display the news entries
while ($row = mysqli_fetch_assoc($result)) {
    echo "<h2>{$row['title']}</h2>";
    echo "<p>{$row['content']}</p>";
    echo "<p>Date: {$row['date']}</p>";
}