Jump to content

[SOLVED] Listing rows in a table in reverse order


DavidGS

Recommended Posts

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.