ebchost Posted June 18, 2011 Share Posted June 18, 2011 Pgination value for $X = 1 is: first, -2, -1, 0, [1], 2, 3, 4, last Pagination value for $x = $total_pages first, 34, 35, 36, [37], 38, 39, 40, last Note: I have 37 pages. <?php $range = 3; for($x=($page - $range); $x < (($page + $range) + 1); $x++) { ?> <div style=' text-align: center; float:left; font-family: verdana; width: 20px; padding: 5px; margin: 1px; border-style:solid; border-width: 1px; border-color:#C8C8C8;'> <?php echo ($x == $page) ? '<strong><a href="index.php?page='.$x.'"> '.$x.' </a></strong>' : '<a href="index.php?page='.$x.'"> '.$x.' </a> '; ?> </div> <?php } ?> How to solve this problem? Quote Link to comment https://forums.phpfreaks.com/topic/239714-pagination-x-0-and-x/ Share on other sites More sharing options...
Fadion Posted June 18, 2011 Share Posted June 18, 2011 Try this code. <?php $page = 1; $total = 37; $range = 3; if ($page > 1) { echo 'Previous '; } for ($i = $page - $range; $i < $page + $range; $i++) { if ($i > 0 and $i <= $total) { if ($i == $page) { echo "[$i] "; } else { echo "$i "; } } } if ($page < $total) { echo 'Next'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239714-pagination-x-0-and-x/#findComment-1231421 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.