Hola Otland!
Im working on a website for my project and on my homepage I wanted to display a "latest news section" something like:
Pic from : Wayfinder - Join the Closed Beta on PlayStation® and PC (https://www.playwayfinder.com/en)
Well anyways so I came up with this code :
This does work, but I got no clue on how to make it 3, since now Im only displaying one you know. And I could just repeat the code 3 times but that feels like a bad way, could probably do some loop thing but Im very newbie when it comes to php.
So in short. Im asking for some feedback on how I would maybe improve this code + loop it 3 times outputting the 3 latest news instead of just the latest news.
Information: Im using latest MyAAC and Tfs 1.4
As always. Thanks a lot for reading! Have an amzing rest of your day! <3
Im working on a website for my project and on my homepage I wanted to display a "latest news section" something like:
Pic from : Wayfinder - Join the Closed Beta on PlayStation® and PC (https://www.playwayfinder.com/en)
Well anyways so I came up with this code :
PHP:
<?php $fetch_from_db = true;
$news_db = $db->query('SELECT `title`,`body`,`category`, `date`, `player_id`, `id`, `article_image` FROM `myaac_news` ORDER BY `date` DESC LIMIT 1');
$news = array();
foreach ($news_db as $news)
$news[] = array('title' => $news['title'], $news['player_id'], 'article_image' => $news['article_image'], 'body' => $news['body'], 'category' => $news['category'], 'date' => $news['date']);
$query = $db->query('SELECT `name` FROM `players` WHERE id = ' . ($news['player_id']) . ' LIMIT 1');
if ($query->rowCount() > 0) {
$query = $query->fetch();
$author = $query['name'];
}
echo '<a href="' . BASE_URL . '?news/archive/' . $news['id'] . '><div class="news-card">' . date("d-m-Y H:i:s", $news["date"]) . '<h2>' . $news["title"] . '</h2><h3>Author: ' . $author . '</h3></div></a>'
So in short. Im asking for some feedback on how I would maybe improve this code + loop it 3 times outputting the 3 latest news instead of just the latest news.
Information: Im using latest MyAAC and Tfs 1.4
As always. Thanks a lot for reading! Have an amzing rest of your day! <3