Dave2711 Posted August 26, 2009 Share Posted August 26, 2009 Hi sorry about this, bit of a silly question but can't for the life of me figure out how to do it.. Basically all my entries on my database have a unique ID, and I want my page to sort them in order from highest to lowest. So at the minute with <?php $pagenum = $_GET['pagenum']; if(!isset($pagenum)){ $pagenum = 1; } $data = mysql_query("SELECT * FROM news") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1){ $pagenum = 1; } elseif ($pagenum >= $last){ $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM news $max") or die(mysql_error()); $next = $pagenum+1; while($info = mysql_fetch_array( $data_p )) { echo "<tr><td width=100% background=images/bg3.jpg border=1>"; echo "<h3>" . $info['n_title'] . "</h3>"; echo "" . $info['n_dsc'] . "<br>"; echo "<br><b>Author: <font color=#A335EE>" . $info['n_author'] . "</font> /"; echo "/ Date: <font color=#A335EE>" . $info['n_date'] . "</font></b>"; echo "<br></td></tr>"; } echo "</table><br><br>"; echo "<center><b> Page $pagenum of $last </b></font><br>"; if ($pagenum == 1) { } else { echo "<b>"; echo " "; echo " "; $previous = $pagenum-1; echo "<center><a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Newer Posts</a></center></b>"; } echo ""; if ($pagenum == $last) { } else { echo " <center><b><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Older Posts »</a></center>"; echo " "; echo " "; } ?> It sorts them in order 1, 2, 3, 4, 5 etc. But id like them to show as 5, 4, 3, 2, 1 as I want it to list news that is stored on the database. Thanks very much in advance Quote Link to comment https://forums.phpfreaks.com/topic/171949-realy-noob-question-when-sorting-mysql-results/ Share on other sites More sharing options...
Mark Baker Posted August 26, 2009 Share Posted August 26, 2009 SELECT * FROM news ORDER BY id DESC Quote Link to comment https://forums.phpfreaks.com/topic/171949-realy-noob-question-when-sorting-mysql-results/#findComment-906661 Share on other sites More sharing options...
Dave2711 Posted August 26, 2009 Author Share Posted August 26, 2009 Ahhh, i think i knew that too lol.. thanks very much, think I must have come across it on google and thought it was something else. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/171949-realy-noob-question-when-sorting-mysql-results/#findComment-906663 Share on other sites More sharing options...
Maq Posted August 26, 2009 Share Posted August 26, 2009 Ahhh, i think i knew that too lol.. thanks very much, think I must have come across it on google and thought it was something else. Thanks again This was actually a MySQL question, which I moved. If this is resolved please mark as so. Quote Link to comment https://forums.phpfreaks.com/topic/171949-realy-noob-question-when-sorting-mysql-results/#findComment-906669 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.