How can PHP be used to display news from a database, with older news displayed normally and newer news in bold?
To display news from a database with older news displayed normally and newer news in bold, you can achieve this by adding a conditional statement in your PHP code to distinguish between older and newer news based on a certain criteria such as date. You can then apply different HTML formatting to the news items based on this condition.
<?php
// Assuming $newsItems is an array of news items fetched from the database
foreach ($newsItems as $news) {
if ($news['date'] > '2022-01-01') {
echo '<strong>' . $news['title'] . '</strong><br>';
} else {
echo $news['title'] . '<br>';
}
}
?>
Keywords
Related Questions
- Are there any recommended tutorials or resources for sending HTML emails using PHP mail()?
- What resources or examples can be found in the PHP manual to help with sorting arrays and manipulating elements?
- What are some best practices for handling UNIX timestamps in PHP to avoid incorrect date conversions?