What are the best practices for displaying new forum posts at the top rather than the bottom?

To display new forum posts at the top rather than the bottom, you can modify the SQL query to order the posts by the timestamp in descending order. This way, the newest posts will be displayed first.

// Assuming you have a database connection established

// Retrieve forum posts from the database and order them by timestamp in descending order
$sql = "SELECT * FROM forum_posts ORDER BY timestamp DESC";
$result = mysqli_query($conn, $sql);

// Display the forum posts
while($row = mysqli_fetch_assoc($result)) {
    echo "<div class='forum-post'>";
    echo "<h3>" . $row['title'] . "</h3>";
    echo "<p>" . $row['content'] . "</p>";
    echo "</div>";
}