chriscloyd Posted April 29, 2012 Share Posted April 29, 2012 I am trying to do my own pagination script to better learn php i do need some help.. First let me explain my goal, then show you the code I have which is not working. I have 5 blogs per page; I have at least 30 blogs in the database for testing purpose; I want the pagination to go as shown if you are first viewing the blog no page selected it will show [1] 2 3 4 5 ... Last Page if you for example choose page three it will show 1 2 [3] 4 5 ... Last Page Now what is happening when you click on page 5 or 6 it does First Page... 4 5 [6] When I would like it to show First Page... 2 3 4 5 [6] or 2 3 4 [5] 6 here is my code <?php //if current page != 1 show first page link $Show .= ($this->CurPage != 1 ? "<a href=\"?module=blog&page=1\">First Page</a>... " : ""); //We need the number of start for the for statement //We need to check if the number of pages excedes three if it does then make the start minus 2 of the current page $Start = (($this->CurPage - 2) >= 1 ? $this->CurPage - 2 : 1); //We need the end page for the for statement $End = (($this->CurPage + 2) <= $this->NumOfPages ? $this->CurPage + 2 : $this->NumOfPages); //Run End Again to make sure $NewEnd = ($End <= 3 && $this->NumOfPages > 5 ? $End + 2 : $End); //Run Start again to make sure $NewStart = ($this->CurPage >= ($this->NumOfPages - 2) ? $Start - 2 : $Start); for ($i = $NewStart; $i <= $NewEnd; $i++) { $Show .= ($i == $this->CurPage ? "<a href=\"?module=blog&page={$i}\"><strong>[{$i}]</strong></a> " :"<a href=\"?module=blog&page={$i}\">{$i}</a> " ); } //If More than one page and you are not on the last page $Show .= ($this->CurPage != $this->NumOfPages && $this->NumOfPages > 1 ? " ...<a href=\"?module=blog&page={$this->NumOfPages}\">Last Page</a>" : ""); return $Show; ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 29, 2012 Share Posted April 29, 2012 Is this your code? Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted April 29, 2012 Author Share Posted April 29, 2012 yes it is Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 29, 2012 Share Posted April 29, 2012 Chris, I'm confused how that could be, since you're using a bunch of constants and arithmetic that explain the behavior you are complaining about. Let's just focus on this: $Start = (($this->CurPage - 2) >= 1 ? $this->CurPage - 2 : 1); Substitute '5' for $this->CurPage, and it's clear that you set $Start to '3'. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted April 29, 2012 Author Share Posted April 29, 2012 I guess, I am lost at what you are asking or helping with. I am trying to always show 5 Results. When I am on page one it will only show [1] 2 3 when I am on page 6 it will only show 4 5 [6]. So I guess I must just be completely confused or what. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 29, 2012 Share Posted April 29, 2012 Well, let me try this a different way... You need to put in some debugging statements to figure out what values you have at certain points in your code. What debugging would be helpful, at what places? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 30, 2012 Share Posted April 30, 2012 Is this your code? I think you mean to ask "Did you write this code" which is bound to elicit a "No". 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.