I'm basically working on a pagination function. Here's what I have so far:
PHP Code:<?php
function printPageIndexes($currentPage, $totalPages, $theURL, $pageGET, $printExtras="")
{
if ($printExtras!="")
{
if ($currentPage!=1)
{
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . '"=1"><<</a> ';
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . ($currentPage-1) . '"><</a> ';
}
}
if ($totalPages >=10)
{
if ($currentPage<=5 || $currentPage>=($totalPages-5))
{
while($i <= $totalPages)
{
if ($i!=$currentPage)
{
// ******************************
if ($currentPage==1 || $currentPage==$totalPages)
{
if ($i <=5 || $i >=($totalPages-5))
{
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . $i . '">' . $i . '</a> ';
}
else
{
if (!$dotsPrinter)
{
$dotsPrinter=true;
$toScreen = $toScreen . '[...]';
}
}
// ******************************
}
else
{
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . $i . '">' . $i . '</a> ';
}
}
else
{
$toScreen = $toScreen . $i;
}
$i++;
}
}
}
else
{
while($i <= $totalPages)
{
if ($i!=$currentPage)
{
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . $i . '">' . $i . '</a> ';
}
else
{
$toScreen = $toScreen . $i;
}
$i++;
}
}
if ($printExtras!="")
{
if ($currentPage!=$totalPages)
{
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . ($currentPage+1) . '">></a> ';
$toScreen = $toScreen . ' <a href="' . $theURL . $pageGET . "=" . $totalPages . '">>></a> ';
}
}
return $toScreen;
}
It's not finished yet as you can tell.
I basically want to get results like this:
1 2 3 4 5 [...] 56 57 58 59 60 61
or
1 2 3 4 5 [...] 26 27 28 29 30 31 32 33 34 35 36 [...] 56 57 58 59 60 61
or
1 2 3 4 5 6 7 8 9 10 11 12 [...] 56 57 58 59 60 61
or
1 [...] 3 4 5 6 7 8 9 10 11 12 13 [...] 56 57 58 59 60 61
Where the bolded number is the current page.
It's basically show 5 pages surrounding the current page, unless it's within 5 of the first page, or the total pages.
My problem is that I can't figure out how to do it.
I'm going to keep trying to work it out, but any help is appreciated.




.
Reply With Quote