2
I am developing a Site with CMS. Everything works perfectly just that I would like the latest posts to be at the top of the page. What’s happening now is that the last posts go to the bottom of the page just wanted the order to be opposite.
PHP Class "Article"
<?php
class Article {
public function fetch_all() {
global $pdo;
$query = $pdo->prepare("SELECT * FROM articles");
$query->execute();
return $query->fetchAll();
}
public function fetch_data($article_id) {
global $pdo;
$query = $pdo->prepare("SELECT * FROM articles WHERE article_id=?");
$query->bindValue(1, $article_id);
$query->execute();
return $query->fetch();
}
}
?>
index php.
<?php
include_once('includes/connection.php');
include_once('includes/article.php');
$article = new Article;
$articles = $article->fetch_all();
?>
<html>
<head>
<title>CMS Tutorial</title>
<link rel ="stylesheet" href="assets/style.css"/>
</head>
<body>
<div class="container">
<a href="index.php" id ="logo">CMS</a>
<ol>
<?php foreach ($articles as $article) { ?>
<li>
<?php echo $article['article_title']; ?>
- <small>
posted <?php echo date('l jS', $article['article_timestamp']); ?>
</small>
</li>
<p><?php echo $article['article_content']; ?></p>
<?php }?>
</ol>
<br>
<small><a href="admin">admin</a></small>
</div>
</body>
</html>
You either sort by date or by insertion id?
– renedet