dropfaith Posted October 10, 2008 Share Posted October 10, 2008 so im making a news section and followed the Pagenation tutorial from Crayon violet here on php freaks http://lawrenceguide.org/news.php heres my link what im trying to do is get it to start on the most recent one and only show the links going back instead of how it is now how it shows the next buttons and most recent i want to reverse how this works So pull the highest id first if that didnt make sense i think the link will clear up alot <?php // includes include("template/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM news"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 1; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM news order by Id desc LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo "<div class=\"story\">"; echo "<div class=\"title\">". $list['Title'] . "</div>"; echo "<div class=\"date\">". $list['Date'] . "</div>"; echo "<div class=\"fullnews\">". $list['News'] . "</div>"; } // end while echo "<div class=\"date\" style=\"text-align:center\">"; /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>Oldest News</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous Page</a> "; } // end if ///////////////////////////////////////////////////// // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next Page</a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Most Recent</a> "; } // end if /****** end build pagination links ******/ echo "</div>"; echo "</div>"; ?> Link to comment https://forums.phpfreaks.com/topic/127878-solved-pageination/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.