peerData Posted September 12, 2009 Share Posted September 12, 2009 I am trying to display, well I have succeeded in doing to, the information from a DataBase Table. However I need to reverse the displaying so that it shows the Newest entries first and the Oldest entries last. Below is the code I have. Any assistance in this would be much appreciated. mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $data = mysql_query("SELECT * FROM post") or die(mysql_error()); Print "<table border=0 cellpadding=0>"; while($result = mysql_fetch_array( $data )) { Print "<tr bgcolor=grey>"; Print "<td>ID: "; Print "".$result['id'] . "</td></tr>"; Print "<td>Date Submitted: "; Print "".$result['day'] . " - "; Print "".$result['month'] . " "; Print "".$result['date'] . ", "; Print "".$result['year'] . "</td></tr>"; Print "<td>Submitted by: "; Print "".$result['name'] . "</td></tr>"; Print "<td>Topic: "; Print "".$result['topic'] . "</td></tr>"; Print "<td>Subject: "; Print "".$result['subject'] . "</td></tr>"; Print "<td>Info Given: "; Print "".$result['info'] . "</td></tr>"; Print "<td>Issue Resolved: "; Print "".$result['resolved'] . "</td></tr>"; Print "<td>"; Print "<hr>" . "</td></tr>"; } Print "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/174022-need-to-reverse-the-results/ Share on other sites More sharing options...
ldb358 Posted September 12, 2009 Share Posted September 12, 2009 try: mysql_query("SELECT * FROM post ORDER BY date DESC") Quote Link to comment https://forums.phpfreaks.com/topic/174022-need-to-reverse-the-results/#findComment-917336 Share on other sites More sharing options...
peerData Posted September 12, 2009 Author Share Posted September 12, 2009 try: mysql_query("SELECT * FROM post ORDER BY date DESC") I done this, cleared my data and tried again, I got 2nd Submit: 70 3rd Submit: 71 4th Submit: 72 1st Submit: 69 Since the ID is autoinc I changed the date to id and it is now showing correctly. So instead of mysql_query("SELECT * FROM post ORDER BY date DESC") I have mysql_query("SELECT * FROM post ORDER BY id DESC") And now to the next task at hand. Thank You VERY much! Quote Link to comment https://forums.phpfreaks.com/topic/174022-need-to-reverse-the-results/#findComment-917343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.