Reversing order of a mySQL query.

They have: 45 posts

Joined: Feb 2002

I've been scrounging the web for about an hour now, but I just can't find it, and I can't remember what it is. I want to reverse the order so that the guestbook displays the latest entry first. Right now it displays the latest entry last, I just need to reverse it.

Thanks.

<?php
$connection
= @mysql_connect(\"localhost\", \"*****\", \"********\");
if (!
$connection) {
  echo( \"<P>Unable to connect to the database server at this time.</P>\" );
  exit();
}
$selectdb = mysql_select_db(\"sonofthor_com\", $connection);
if (!@selectdb) {
  echo( \"<P>Unable to locate the main database at this time.</P>\" );
  exit();
}

Echo ('
<html>
<body bgcolor=\"black\" link=\"darkseagreen\" vlink=\"darkseagreen\" alink=\"lightseagreen\" text=\"lightblue\">
<font face=\"verdana\" color=\"lightblue\" size=\"4\">My Guestbook!</font><br><br>
<font face=\"verdana\" color=\"lightblue\" size=\"1\"><a href=\"guestbook.php\" target=\"_self\">Reload...</a><br>
<a href=\"http://www.sonofthor.com/fm666/sign.php\" target=\"_blank\">Sign My Guestbook</a><br><br>
');

$results = mysql_query (\"SELECT id, name, comments FROM fm666_book ORDER BY id\");
While (
$row = mysql_fetch_array($results)) {
 
$id = $row[\"id\"];
 
$name = $row[\"name\"];
 
$comments = $row[\"comments\"];
  Echo (\"
<b><a href=\\"
aim:goim?screenname=$name\\">$name</a> said:</b><br>
$comments<br>
  \");
}
?>

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Try adding a "DESC" to your SQL statement:

"SELECT id, name, comments FROM fm666_book ORDER BY id DESC"

They have: 45 posts

Joined: Feb 2002

Ah, thanks I knew it was simple.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.