I am trying to add "Go to first page" and "Go to last page" in this code. Obviously "Go to first page" isn't an issue, but I am not sure I know how to make it do "Go to last page". for($j=$ini;$j<$end;$j++)if(isset($entries[1][$j]))echo str_replace($ovo,$sovim,$entries[1][$j]); if($maxp>-1){ echo '<p>'.strstr($fcontent,'<!--').' <div class="pager"> '; $gap = ""; for($j=0;$j<$maxp+1;$j++){ if($j==0||$j==$maxp||($j-$page)*($j-$page)<26){ echo $gap; $gap = ""; if($j!=$page)echo " <a href=\"?view=page&pagename=updatemain&p=".$j.$si."\"><span class=\"pagerlink\">".($j+1)."</span></a> " ; else echo " <span class=\"current\">".($j+1)."</span> " ; } else $gap = "...</div>"; } echo '</p>'; } } Code (markup):
I had a wee play with your code because the way you have it laid out it's damn hard to read - you really don't need to be escaping all those quote marks for($j=$ini; $j<$end; $j++){ if(array_key_exists($j, $entries[1])){ echo str_replace($ovo, $sovim, $entries[1][$j]); } if($maxp > -1){ echo '<p>'.strstr($fcontent,'<!--').' <div class="pager"> '; $gap = ""; for($j=0; $j<$maxp+1; $j++){ if($j==0||$j==$maxp||(($j-$page)*($j-$page)<26)) { echo $gap; $gap = ""; if($j!=$page) { echo " <a href='?view=page&pagename=updatemain&p={$j}{$si}'><span class='pagerlink'>".($j+1)."</span></a> " ; } else { echo " <span class='current'>".($j+1)."</span> " ; } } else { $gap = "...</div>"; } } echo " <a href='?view=page&pagename=updatemain&p={$maxp}'><span class='pagerlink'>".($maxp)."</span></a> " ; echo '</p>'; } } Code (markup): Not knowing what some of the variables are I was a little in the dark. Is $maxp the length of the article? If not, you might just have to loop through the array to get the maximum number of pages if there's no easy maths.
@sarahk do you mind checking your code again? It goes into a blank page. I am wondering if there's an extra ' or " somewhere or maybe something isn't closed properly.
Actually I simplified it, seems to be working: for($j=$ini;$j<$end;$j++)if(isset($entries[1][$j]))echo str_replace($ovo,$sovim,$entries[1][$j]); if($maxp>-1){ echo '<p></p>'.strstr($fcontent,'<!--').' <div class="pager"> '; $gap = ""; echo " <a href=\"?view=page&pagename=updatemain&p=0\"><span class=\"pagerlink\">First</span></a> "; for($j=0;$j<$maxp+1;$j++){ if($j==0||$j==$maxp||($j-$page)*($j-$page)<5){ echo $gap; $gap = ""; if($j!=$page)echo " <a href=\"?view=page&pagename=updatemain&p=".$j.$si."\"><span class=\"pagerlink\">".($j+1)."</span></a> " ; else echo " <span class=\"current\">".($j+1)."</span> " ; } else $gap = "..."; } echo "<a href=\"?view=page&pagename=updatemain&p={$maxp}\"><span class=\"pagerlink\">Last</span></a></div>"; } } Code (markup):
And that's the part I didn't know how to get in there. Thanks for showing me how. And the escaping part doesn't bother me. I just needed a quick fix...
Well... I cleaned it up a bit (you really need to learn the difference between single and double quotes ) for ($j = $ini; $j < $end; $j++) { if (isset($entries[1][$j])) { echo str_replace($ovo,$sovim,$entries[1][$j]); } if ($maxp > -1) { echo '<p></p>'.strstr($fcontent,'<!--').' <div class="pager">'; $gap = ''; echo '<a href="?view=page&pagename=updatemain&p=0" class="pagerlink">First</a>'; for ($j = 0; $j < $maxp+1; $j++) { if ( $j == 0 || $j == $maxp || ($j - $page)*($j - $page) < 5) { echo $gap; $gap = ''; if ($j != $page) { echo '<a href="?view=page&pagename=updatemain&p='.$j.$si.'" class="pagerlink">'.($j+1).'</a>'; } else { echo '<span class="current">'.($j+1).'</span>'; } } else { $gap = '...</div>'; } } echo '<a href="?view=page&pagename=updatemain&p='.{$maxp}.'" class="pagerlink">Last</a>'; } } PHP: Also, mixing using the curly brackets and not using them leaves a mess. The same does the different formatting from almost line to line. Also, why do you have the span inside the <a>-tag? There's no need for it, unless you're doing something weird - just put the class on the a-tag. And... the empty <p></p> before the start of the <div>... what's that for?
Good points, will clean it up later. I just found the code I needed and wanted to get it working first like I wanted it to. Thank you for your code. PS it's always hard for me to set a best answer when both people gave me really good solutions. So I'll just leave it at that. Yay! Everyone wins!