Okay, I set up this little "Post a Comment" page on my website, and I've set up where you can post the comment and then it displays all the comments.
Right now, they are sorted with the oldest on top, but I would rather have the newest on top. How could I do this?
Here's the page:
http://mscreashuns.savefile.com/summerbreeze/discuss.php
and here's the code I use for that page:
<? include("header.inc");
echo "<marquee scrollamount=5 behavior=slide><p align=left>DISCUSS SUMMERBREEZE</p></marquee>";
echo "<a href='insert_comment.php'>Post a comment</a><br /><br />";
if($submit != "") {
echo "<p align=left>Thank you for your comments!</p>"; }
// Make a MySQL Connection
mysql_connect("HOST_NAME", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DATABASE_NAME") or die(mysql_error());
// Get all the data from the "comments" table
$result = mysql_query("SELECT * FROM comments")
or die(mysql_error());
echo "<table border='0'>";
echo "<tr> <th></th> <th></th> </tr> <tr> <th></th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
if($row['url'] == "") {
echo "<tr><td><p align=left>Posted by: ";
echo $row['name'];
echo "</p></td><td>";
}
else {
echo "<tr><td><p align=left>Posted by: <a href='";
echo $row['url'];
echo "'>";
echo $row['name'];
echo "</a></p></td><td>"; }
echo "</td></tr><tr><td>";
echo $row['comment'];
echo "<hr noshade color=white width=75%></td></tr>";
}
echo "</table>";
// Make a MySQL Connection
mysql_connect("HOST_NAME", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DATABASE_NAME") or die(mysql_error());
if ((($_POST['name'] == "") or ($_POST['email'] == "") or
($_POST['comments'] == "")) && ($_POST['submit'] == "Submit")) {
echo "<font color=red>There was an error in the data you submitted. Please go back and fill in all the required fields.</font>";
die(); }
if ($_POST['submit'] == "Submit") {
// Insert a row of information into the table "comments"
mysql_query("INSERT INTO comments
(name, email, url, comment) VALUES('$name', '$email', '$url', '$comments') ")
or die(mysql_error()); }
include("footer.inc"); ?>