itsureboy Posted January 28, 2007 Share Posted January 28, 2007 I want to know how I can sort out my rows when php prints it from MySQL in a descending manner so the last rows I insert in my MySQL table is displayed on the first page. Right now its displaying it in the order in which it was inserted. Any help please ???. Thank You....Here is the pagination php code:<br />[code]<?phpinclude 'db.php';if(!isset($_GET['page'])){ $page = 1;} else { $page = $_GET['page'];}$max_results = 2;$from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");while($row = mysql_fetch_array($sql)){ // Build your formatted results here. echo $row['title'];}$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);$total_pages = ceil($total_results / $max_results);echo "<tr>";echo stripslashes("<td class=\"leftnavi2\" colspan=\"1\"> ");echo "</td>";echo stripslashes("<td class=\"titlesection2\" colspan=\"4\"> ");if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }}if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";}echo "</center>";echo "</td>";echo "</tr>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/36082-output-rows-in-pagination-in-descending-manner/ Share on other sites More sharing options...
.josh Posted January 28, 2007 Share Posted January 28, 2007 SELECT * FROM pages order by desc LIMIT $from, $max_results Link to comment https://forums.phpfreaks.com/topic/36082-output-rows-in-pagination-in-descending-manner/#findComment-171281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.