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 basic, and work.
PHP Code:
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);// number of pages for($i = 0; $i <= ($pages); $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>"; $ListingTable .= "</table><br><br>\n"; } else // rows <= bypage (no navbar required) { $ListingTable .= "<br><br>\n"; } } // lrows >0
Now, I managed to get this code to limit the number of pages, but unfortunately has an error, because the pages are not correct.
I think it is in the code. As an example of 10 pages, the first page does not appear, and when I click on page 2, the result of this page no longer appears the page 3 | 4 | 5 ... , but the page 7, and no further.
Is there some simple code that can integrate this. Or does missing some function in the code?
The code is:
PHP Code:
$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 = 5; $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 = array(); $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 "; } } var_dump( $links ); $links2 = implode(" | ", $links); $ListingTable .= $links2; $ListingTable .= "| </td></tr>"; $ListingTable .= "</table><br><br>\n"; } else // rows <= bypage (no navbar required) { $ListingTable .= "<br><br>\n"; }
Someone can help me, please!
Thanks for attention
MM
|