So I've been using PHP to list my website's articles via MySQL. The problem is, the posts are supposed to be listed with newest at the top, but instead oldest posts are at the top. How can I change this. Here is a snippet of source code:
<?php foreach ($posts as $post): ?>
<div class="container">
<h2 class="title"><a href=""><?php echo htmlspecialchars($post['title'], ENT_QUOTES, 'UTF-8'); ?></a></h2>
<p class="date"><?php echo htmlspecialchars($post['date'], ENT_QUOTES, 'UTF-8'); ?></p>
<div class="body">
<p><?php echo htmlspecialchars($post['content'], ENT_QUOTES, 'UTF-8'); ?></p>
</div>
</div>
<?php endforeach; ?>
try {
$sql = 'SELECT id, title, date, content FROM post';
$result = $pdo->query($sql);
} catch (PDOException $e) {
$error = 'Error connecting to database server: ' . $e->getMessage();
exit();
}