ngreenwood6 Posted October 13, 2008 Share Posted October 13, 2008 I am new to php but know some of the basics. I am trying to learn so I am trying to do some pagination. I have this code: <?php if($page == 1) { echo "First "; } else { echo "<a href='banking.php?page=1'>First</a> "; } for($i=1; $i <= $num_pages; $i++) { echo "<a href='banking.php?page=$i'>$i</a> "; } if($page == $num_pages) { echo "Last "; } else { echo "<a href='banking.php?page=$num_pages'>Last</a> "; } ?> This works perfectly. However I would like something a little more. Right now it shows "first" "page numbers" "last". if you are on the first page or the last page it does not display them as a link. i would like it to do that for the page numbers. Right now no matter what page you are on it shows it as a link. I do not want it to be a link if you are on that page. Any help is appreciated. If you need any additional information please let me know. Link to comment https://forums.phpfreaks.com/topic/128201-solved-pagination/ Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 Add an if statement like this: if ($i == $page) { echo "$i " } else { echo "<a href='banking.php?page=$i'>$i</a> "; } Link to comment https://forums.phpfreaks.com/topic/128201-solved-pagination/#findComment-663956 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 That is what I was thinking but I kept saying no that wont work. Now that I see it on the screen it makes sense because it keeps adding the pages until it gets to the number of pages. So thats why the if and the else will be executed, because my thinking was that only the if would be executed but now I see. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/128201-solved-pagination/#findComment-663964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.