phpcode Posted July 16, 2009 Share Posted July 16, 2009 I'm trying to create a news system and I want it to display the three latest news post on the front page but I'm not sure how All the news is arranged by an ID number that starts from 0 for the oldest to how ever many news post there is. I also have a date field so if there's a way to arrange by date could someone tell me? Quote Link to comment https://forums.phpfreaks.com/topic/166161-solved-display-the-three-latest-news-post/ Share on other sites More sharing options...
daveoffy Posted July 16, 2009 Share Posted July 16, 2009 you could try this $qry = "SELECT * FROM `news` LIMIT 3 ORDER BY `id` DESC"; $result = mysql_query($qry)' while($row = mysql_fetch_assoc($result)){ $newstitle = $row['title']; $news = $row['news']; echo $newstitle; echo '<br>'; echo $news; } Quote Link to comment https://forums.phpfreaks.com/topic/166161-solved-display-the-three-latest-news-post/#findComment-876261 Share on other sites More sharing options...
Amtran Posted July 16, 2009 Share Posted July 16, 2009 <?php $query = "SELECT * FROM news LIMIT 3 ORDER BY date DESC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { //etc... } ?> Dang, you beat me to it Dave! And, yes, like I was going to say, ordering it by the ID field works just as well. Quote Link to comment https://forums.phpfreaks.com/topic/166161-solved-display-the-three-latest-news-post/#findComment-876262 Share on other sites More sharing options...
phpcode Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks got it working. Quote Link to comment https://forums.phpfreaks.com/topic/166161-solved-display-the-three-latest-news-post/#findComment-876284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.