我有一个 PHP 代码可以发布我所做的文章,但是从最旧到最新,我需要它从最新到最旧,所以顺序是问题
这是我用来将帖子放入数组的函数:
function getPublishedPosts() {
// use global $conn object in function
global $conn;
$sql = "SELECT * FROM posts WHERE published=true";
$result = mysqli_query($conn, $sql);
// fetch all posts as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $posts;
}
这是代码的可视化部分:
<?php foreach ($posts as $post): ?>
<div class="post" style="margin-left: 0px;">
<img src="<?php echo BASE_URL . '/static/' . $post['image']; ?>" class="post_image" alt="">
<a href="single_post.php?post-slug=<?php echo $post['slug']; ?>">
<div class="post_info">
<h3><?php echo $post['title'] ?></h3>
<div class="post-body-div">
<?php echo html_entity_decode($post['body']); ?>
</div>
<div class="info">
<span><?php echo date("F j, Y ", strtotime($post["created_at"])); ?></span>
</div>
</div>
</a>
</div>
<?php endforeach ?>
繁星coding
料青山看我应如是