Forum Moderators: coopster
This site has been an amazing source for me over the years. I ALWAYS found my answers and never need to post. However this one I cannot find and i know you guys can help.
I want to style my most recent news article differently then the other articles on the page. I am using PHP/MYSQL.
function get_news_feature($where='1=1'){
return db_query("SELECT * FROM `newsfeature` WHERE $where ORDER BY `id` DESC LIMIT 3");
foreach(get_news_feature () as $news){
if($news['here is where i need help'] <= ("")){
echo "<div class='newsphoto'>".$news['photo']."</div>";
echo "<div class='headlinefeature'><a href='/feature.php?id=" . $news[id] ." '>".$news['subject']."</div></a>";
echo "<div class='datefeature'>".$news['date']."</div>";
echo "<div class='authorfeature'>".$news['author']."</div>";
echo "<div class='summaryfeature'>".$news['summary']."</div>";
echo "<div class='readmoref'><a href='/feature.php?id=" . $news[id] ." '>Read More</div></a>";
}else{ echo "<div class='newsphoto2'>".$news['photo']."</div>";
echo "<div class='headlinefeature2'><a href='/feature.php?id=" . $news[id] ." '>".$news['subject']."</div></a>";
echo "<div class='datefeature2'>".$news['date']."</div>";
echo "<div class='authorfeature2'>".$news['author']."</div>";
echo "<div class='summaryfeature2'>".$news['summary']."</div>";
echo "<div class='readmoref2'><a href='/feature.php?id=" . $news[id] ." '>Read More</div></a>";
}
}
.... the "here is where i need help" is the most recent news article in the database. And of course where i need the help..i think. So i want to style the most recent article differently on the same page as the other articles.
Thanks everyone
$out = ''; // initialize
foreach(get_news_feature () as $news){
if (!$out) {
$out .= "<div class='newsphoto'>".$news['photo']."</div>";
// etc, etc, etc.
} else {
// other formatting
}
}
echo $out;
is there anyway to get the most recent article id
Well, I guess the most recent article would indeed have the highest id number if it was an automatic incrementing column. And when you ORDER BY that column in DESC order you would have the latest values first in your result set. You could also have a date or timestamp in your table and ORDER BY <date field here> DESC.
The example logic I showed was how to recognize if the first one had been read in yet. If there is no formatted output on the first loop, we are on the first news article, otherwise we are on 2nd or greater news article(s).