What are some common methods for organizing posts in a PHP guestbook, such as displaying the newest post at the top and the oldest at the bottom?

To organize posts in a PHP guestbook with the newest post at the top and the oldest at the bottom, you can use a database query to retrieve the posts in descending order based on their timestamp. This way, the newest posts will be displayed first. You can then loop through the results and display each post accordingly.

// Assuming $posts is an array of posts retrieved from a database
// Sort the posts in descending order based on their timestamp
usort($posts, function($a, $b) {
    return strtotime($b['timestamp']) - strtotime($a['timestamp']);
});

// Loop through the sorted posts and display each post
foreach ($posts as $post) {
    echo "<div>";
    echo "<p>{$post['content']}</p>";
    echo "<small>{$post['timestamp']}</small>";
    echo "</div>";
}