DavidGS Posted December 26, 2007 Share Posted December 26, 2007 OK, so I have a news system set up on my website and I am using a database to store the news in. It's just one table called "news" and there are 5 columns (id, name, title, contents, date). I am using a while loop to list all the news on the main page, but all the old content stays at the top and the new stuff is at the bottom. I want the new stuff up top and all the old stuff down the bottom. This is the code: $query = "SELECT * FROM news"; $result = mysql_query($query) or die(mysql_error()); while($news = mysql_fetch_array($result)) { print "<br><b>{$news['title']}</b><br>\n"; print "<i>By {$news['name']}</i>.<br>\n"; print "<p>{$news['contents']}</p>\n"; print "<small>{$news['date']}</small><br>\n"; } It works without errors, but as I said, since all the newest records are stored at the bottom of the table, they're listed last instead of first. What loop would I use to list these rows in reverse-order? Link to comment https://forums.phpfreaks.com/topic/83217-solved-listing-rows-in-a-table-in-reverse-order/ Share on other sites More sharing options...
~n[EO]n~ Posted December 26, 2007 Share Posted December 26, 2007 You can change the query SELECT * FROM news ORDER BY `id` DESC; will list the rows in descending order Link to comment https://forums.phpfreaks.com/topic/83217-solved-listing-rows-in-a-table-in-reverse-order/#findComment-423331 Share on other sites More sharing options...
DavidGS Posted December 26, 2007 Author Share Posted December 26, 2007 Thanks, ~n[EO]n~, that's exactly what I needed. Link to comment https://forums.phpfreaks.com/topic/83217-solved-listing-rows-in-a-table-in-reverse-order/#findComment-423332 Share on other sites More sharing options...
fenway Posted December 27, 2007 Share Posted December 27, 2007 But you shouldn't use the ID -- you have a date field!!!!! Link to comment https://forums.phpfreaks.com/topic/83217-solved-listing-rows-in-a-table-in-reverse-order/#findComment-424089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.