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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.