tmworking Posted August 26, 2009 Share Posted August 26, 2009 How can I fix my pagination? Links appear, and reload the page, but when I did an echo $page, even though the url is page=2 the echo is showing page 1. Any help would be awesome! Here are the snippets: if(!$page) $page = 1; $npage = $page - 1; if($c){ $addsql = " AND `cat` = '". $c ."'"; $addhtml = "&c=". $c; } $limit1 = $npage * 10; $limit2 = $npage + 10; echo $page; $q = "SELECT * FROM `comps` WHERE `accepted` = 'Yes'". $addsql ." ORDER BY `time` DESC LIMIT ". $limit1 .", ". $limit2; then display stuff Then $q = "SELECT COUNT(*) FROM `comps` WHERE `accepted` = 'Yes'". $addsql; $r = mysql_query($q); $num = mysql_fetch_array($r); $nbrPages = ceil($num[0] / 10); $i = 1; $maincontent .= "<br />"; // Pagination links. $nbrPages = $nbrPages; $thisPage = ""; include("pagination.php"); $maincontent .= $paginationLinks; Below is pagination code <?php //$nbrPages = 300; //$thisPage = "paginationTest.php"; if(strpos($thisPage, "?") === false) { $separator = "?"; } else { $separator = "&"; } if($nbrPages > 1) { if(isset($_REQUEST['page'])) { $currentPage = $_REQUEST['page']; } else { $currentPage = 1; } // pagination links $links = ""; // the first links // Display the first link separatly or not if($currentPage > 5) { // display the link separatly $links .= "<a href=\"" . $thisPage . $separator . "page=1\">1</a> ... "; if($currentPage < 4) { $strt = 2; } else { $strt = $currentPage-4; } for($i=$strt;$i<$currentPage;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } else { // display the link with the others $links .= ""; if($currentPage <= 4) { $strt = 1; } else { $strt = $currentPage-4; } for($i=$strt;$i<$currentPage;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } // display the current page 'link' $links .= "<b class=\"currentPage\">" . $currentPage . "</b> "; // Display the last link separatly or not if($currentPage < $nbrPages - 4) { // display the link separatly for($i=$currentPage+1;$i<$currentPage+4;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } $links .= " ... <a href=\"" . $thisPage . $separator . "page=" . $nbrPages . "\">" . $nbrPages . "</a>"; } else { // display the link with the others $links .= ""; for($i=$currentPage+1;$i<$nbrPages+1;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } // Next and previous links if($currentPage == 1) { $nextLink = "<span style=\"color: rgb(170, 170, 170);\">Previous page</span>"; } else { $nextLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage - 1) . "\"><< Previous page</a>"; } if($currentPage == $nbrPages) { $previousLink = "<span style=\"color: rgb(170, 170, 170);\">Next page </span>"; } else { $previousLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage + 1) . "\">Next page >></a>"; } $paginationLinks = "<div style=\"font-size:11px;font-family:'Lucida Grande','Lucida Sans Unicode',Verdana,Arial,sans-serif\"> <div style=\"float:left;\">[ Pages: " . $links . " ]</div> <div style=\"float:right;\"> <sup></sup> " . $nextLink . " | " . $previousLink . " <sup></sup> </div> </div>"; } else { $paginationLinks = ""; } ?> Looking forward to learning what I'm doing wrong, thanks! Quote Link to comment Share on other sites More sharing options...
tmworking Posted August 27, 2009 Author Share Posted August 27, 2009 Thought I might add...buying scripts to save time in NOT a good idea, you end up with code like this. Quote Link to comment Share on other sites More sharing options...
tmworking Posted August 28, 2009 Author Share Posted August 28, 2009 In case anyone else ever comes across this, the solution is: if(isset($_GET['page'])) { $page=$_GET['page']; } else { $page=1; } $npage=$page-1; Quote Link to comment 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.