srinivas6203 Posted June 19, 2008 Share Posted June 19, 2008 My question is: I have the Pagination working beautifully, my only complaint is that in the future when there are a lot of submissions, it will display as [First] [Prev] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [Next] [Last] Which is ok, but I would much rather it show up like Google results, by which I mean only lists a few pages in front of the current page. Like so [First] [Prev] 1 2 3 4 5 6 7 8 9 [Next] [Last] and if you are on page 4 [First] [Prev] 4 5 6 7 8 9 10 11 12 [Next] [Last] Unfortunatly for me, I have an idea how I could get this to work, but have not been able to get it right. How would this be done? Here is the code I have right now: if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' /></a> "; $first = " <a href=\"$self?page=1\"><img src='Images/First.jpg' border='0' /></a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' /></a> "; $last = " <a href=\"$self?page=$maxPage\"><img src='Images/Last.jpg' border='0' /></a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table><br>"; } } Link to comment https://forums.phpfreaks.com/topic/110875-customizing-pagination-output/ Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Try this: <?php if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' />[/url] "; $first = " <a href=\"$self?page=1\"><img src='Images/First.jpg' border='0' />[/url] "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $pageNum+9) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' />[/url] "; $last = " <a href=\"$self?page=$maxPage\"><img src='Images/Last.jpg' border='0' />[/url] "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/110875-customizing-pagination-output/#findComment-568854 Share on other sites More sharing options...
samshel Posted June 19, 2008 Share Posted June 19, 2008 not tested , but something like this... $intPagesShown = 10; if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\"><img src='Images/Prev.jpg' border='0' />[/url] "; $firstnum = $pageNum - $intPagesShown /2; if($firstnum < 1) $firstnum = 1; $first = " <a href=\"$self?page=".$firstnum."\"><img src='Images/First.jpg' border='0' />[/url] "; } else { $firstnum = 1; $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\"><img src='Images/Next.jpg' border='0' />[/url] "; $lastnum = $firstnum + $intPagesShown - 1; if($lastnum > $maxPage) $lastnum = $maxPage; $last = " <a href=\"$self?page=$lastnum\"><img src='Images/Last.jpg' border='0' />[/url] "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td width='100' height='50'>" . $first . "</td><td width='75' height='50'>" . $prev . "</td><td width='150' height='50'>" . $nav . "</td><td width='75' height='50'>" . $next . "</td><td width='100' height='50'>" . $last . "</td></tr></table> "; } } Link to comment https://forums.phpfreaks.com/topic/110875-customizing-pagination-output/#findComment-568861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.