Hi friends,
I have a site, where I want to limit the number of pages being viewed.
example:
1 | 2 | 3 | 4 | 5 | 5 | 7 | 8 | 9 | 10 | 11
want to reduce this to:
1 | 2 | 3 | 4 | ... | 10 | 11
I have the code but is giving headaches.
if(!empty($_GET[Start]))
{
$Start = $_GET[Start];
}
else
{
$Start = '0';
}
// limit of links per page
$ByPage = '13';
$rnav = mysql_query($qnav) or die(mysql_error());
$rows = mysql_num_rows($rnav);
if($rows > $ByPage)
{
$ListingTable .= "<table class=\"tlistnav\" border=0 cellspacing=0 align=center width=100% >";
$ListingTable .= "<tr><td align=center><font face=verdana size=2> | ";
$pages = ceil($rows/$ByPage);
$pagesLimit = 10;//Limit of pages
$lowAllow = (int)($Start - ($pagesLimit / 2));
$start = ($lowAllow <= 0) ? 1 : $lowAllow;
$aboveAllow = $start + $pagesLimit;
$until = ($aboveAllow > $pages) ? $pages : $aboveAllow;
for($i = $start; $i <= $until; $i++)
{
$PageStart = $ByPage*$i;
$i2 = $i + 1;
if($PageStart == $Start)
{
$links[] = " <span class=CurrPageIdx>$i2</span>\n\t ";
}
elseif($PageStart < $rows)
{
$links[] = " <a class=BlackLink href=\"search.php?Start=$PageStart&c=$_GET[c]&s=$_GET[s]&search_kw=$_GET[search_kw]&CategoryID=$_GET[CategoryID]&search_district=$_GET[search_district]&search_place=$_GET[search_place]&search_city=$_GET[search_city]&PostID=$_GET[PostID]&zip=$_GET[zip]&old=$_GET[old]\">$i2</a>\n\t ";
}
}
$links2 = implode(" | ", $links);
$ListingTable .= $links2;
$ListingTable .= "| </td></tr>";
//tablefix added </tr> to tlisnav
$ListingTable .= "</table><br><br>\n";
}
else // rows <= bypage (no navbar required)
{
$ListingTable .= "<br><br>\n";
}
Unfortunately the code is giving error, because the first page ( 1 ) does not appear, and when I click on page two so now appears 9 | 10 | 11 and will not appear on the page 1 | or later.
Testing with a limit of 5, the initial result of paging is: 2 | 3 | 4 | 5
In the following pages of error:
Warning: implode () [function.implode]: Invalid arguments passed in C: \ Program Files \ xampp \ htdocs \ teste \ search.php on line 511
line 511 corresponds to the code:
$links2 = implode(" | ", $links);
I would appreciate help from anyone who has a practice in the matter.
Thank you for your kindness in helping ...