Forum Moderators: coopster
As for now how my script works: it queries the DB and give the output with 10 per page, and makes a pagination on the bottom of the page like 1 2 3 4 ...
With some general search terms, i get more then 200 pages returned and it goes from 1 2 ... to 200 on the bottom of the page, this isn't really nice looking, so I was wondering if I can limit the pagination to 11 pagelinks at all times, so if there 200 pages and you're on page 25 you see on the bottom of the page:
< previous 20 21 22 23 24 25 26 27 28 29 30 next>
and if you are on page 29 it would be
< previous 24 25 26 27 28 29 30 31 32 33 34 next>
leaving the current page in the middle of the pagination with 5 previous pagelinks and 5 next pagelinks. And when clicking on previous or next shifting one page. Is this possible?
This is my current pagination:
if ($count > $lperpage) {$linkshtml .= "<p>Page: ";
if ($page > 1) $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($page-1)."\">$pageprev</a> ";
for ($o=1; $o<=ceil($count/$lperpage); $o++) {
if ($page == $o) $linkshtml .= "$o ";
else $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($o)."\">$o</a> ";}
if ($page < ceil($count/$lperpage)) $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($page+1)."\">$pagenext</a> ";
$linkshtml .= "</p>";
}
any help is appreciated!
cheers
Steve
// Store total pages
$totPages = ceil($count/$lperpage);// First 11 pages, if current page is less than 5 pages in
if (($page - 5) < 1)
{
for ($o=1; $o<=11; $o++) {
if ($page == $o) $linkshtml .= "$o ";
else $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($o)."\">$o</a> ";
}
} else if (($page + 5) > $totPages)
{
// Output last 11 pages
for ($o= ($totPages - 11); $o<=$totPages; $o++) {
if ($page == $o) $linkshtml .= "$o ";
else $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($o)."\">$o</a> ";
}
} else {
// Output pages 5 below, and 5 above
for ($o= ($page - 5); $o<=($page + 5); $o++) {
if ($page == $o) $linkshtml .= "$o ";
else $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($o)."\">$o</a> ";
}
}
Untested, but hoping it helps anyway.
So i need to build in a limit when the end has been reached.
I already know the nr of pages by
$totPages = ceil($count/$lperpage);
So i added this extra condition before all yours"
if ($totPages < 11) {
for ($o=1; $o<=ceil($count/$lperpage); $o++) {
if ($page == $o) $linkshtml .= "$o ";
else $linkshtml .= "<a href=\"search.$pext?query=".urlencode($query)."&page=".($o)."\">$o</a> ";
}
}
else {
worked!
thanks again!