Hello,
I was wanting help after many trial and errors I only got this far.
How to display it so it looks like this.
(first page) 1 2 3 4 5 6 7 Next Last
(second page) First Previous 1 2* 3 4 5 6 7 Next Last
right now it looks like this … First Previous 0 1 2 Next Last
Let me know if you need more information.
Thanks in advance
<div id="paging">
<div class="page">
<?php if ($pageNum_getDisplay > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, 0, $queryString_getDisplay); ?>">First</a>
<?php } // Show if not first page ?></div>
<div class="page">
<?php if ($pageNum_getDisplay > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, max(0, $pageNum_getDisplay - 1), $queryString_getDisplay); ?>">Previous</a>
<?php } // Show if not first page ?></div>
<div class="page">
<?php for ($i=0;$i<=$pageNum_getDisplay;$i++){
if ($pageNum_getDisplay==$i)
echo ($i);
else
echo "<a title='Page $i' href='?pageNum_getDisplay=$i'><strong>$i</strong></a>";
} ?> </div>
<div class="page">
<?php if ($pageNum_getDisplay < $totalPages_getDisplay) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, min($totalPages_getDisplay, $pageNum_getDisplay + 1), $queryString_getDisplay); ?>">Next</a></div>
<div class="page">
<?php } // Show if not last page ?>
<?php if ($pageNum_getDisplay < $totalPages_getDisplay) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, $totalPages_getDisplay, $queryString_getDisplay); ?>">Last</a>
<?php } // Show if not last page ?>
</div>
</div>
Hi starlion,
I tried using the asterik but it doesn’t seem to work Iget error.
I tried creating another php set telling it to display page numbers larger than the current page and Igot an infinite numbers causing it to slow down and freeze browser. Is there a way to limit it to only the amount of pages I have?
<div class=“page”>
<?php for ($i=0;$i<=$pageNum_getDisplay;$i++){
if ($pageNum_getDisplay==$i)
echo ($i);
else
echo “<a title=‘Page $i’ href=‘?pageNum_getDisplay=$i’><strong>$i</strong></a>”;
} ?>
<?php for ($i=0;$i>=$pageNum_getDisplay; $i++){
if (pageNum_getDisplay < $i)
echo “<a title=‘Page $i’ href=‘?pageNum_getDisplay=$i’>$i</a>”;
} ?> </div>
this is the code i have currently that displays endless amount of pages beyond current page. i need to create a stop to this to the exact amount of pages and only show 5-10 pages at a time.
for the * i just replaced the $i with what the portion of code you picked out from my thing.
so you put echo(“*”); ? Should work.
That piece of code you show doesnt say where $pageNum_getDisplay comes from. It must be set further up in the script.
This loop reads: “Start at 0. Go until you equal the current page. Step by 1”.
From your post, you want to do exactly 5 pages, ideally centered around the current page.
I’ll give you the logic, and lets see if you can implement it.
So we need to do some maths. We need to know a start (which i’m going to call $start . Feel free to call it whatever you want.), and an end.
Now from your code we know a couple of things:
$totalPages_getDisplay is the total number of pages.
$pageNum_getDisplay is the current page.
5 is the number of links you want to display.
I’m going to give you a 3-piece piecemeal function for $start:
$start =:
0, if current page <= 2
totalpages - 5, if current page >= totalpages-2
currentpage - 2, otherwise.
And one for end…
end =:
$start+5, if totalpages > 5
totalpages, otherwise.
Okay I got it to work with this code, but is there anyway to make it display the current page as 1 instead of 0 and have it still put up pageNum_getDisplay=0.
well your ifs arnt actually doing anything at the moment.
As far as making it display one value higher, easiest way is to add 1 to maxpages, subtract 1 from the currentpages value used to pull page content, and then your minimum start should be 1.
Hi StarLion,
I have another question. Is there a way to only display the pages I have instead of what it’s doing now and showing 5 automatically. Thanks.