Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Site Navigation Code Examples

Navigation through a page-list, which is returned by a Database

Navigation through a page-list, which is returned by a Database <?php //* // Function, which automaticly prints a page-navigation, // when there are more entries which are returned from // a database then should be printed on a page // // // The function needs three parameter // // 1. allEntries: Integer, Number of all DB-Entries // 2. limitBy: Integer, Number of Entries, which are printed on one Page // 3. limitStart: Integer, Offset // // function showPageNavigation($allEntries, $limitStart=0, $limitBy=20) { $lastPageEntries = ($allEntries % $limitBy); $allPages = round(($allEntries - $lastPageEntries) / $limitBy)+1; if($lastPageEntries>0 and $allPages==0) {$allPages=$allPages+1;} $thisPage = round(($limitStart+$limitBy) / $limitBy); print "<b><br>Page ".$thisPage." of ".$allPages."<br><br></b>"; if($allEntries > $limitBy) { print "<b>Pages:</b> "; for($entryNr=1; $entryNr<=$allPages; $entryNr++) { $startPage = ($entryNr * $limitBy) - $limitBy; if($thisPage!=$entryNr){print "<b><a href=\"".$PHP_SELF."?limitStart=".$startPage."\">".$entryNr."</a></b> ";} else{print "<b>".$entryNr."</b> ";} } } $startNext = $thisPage * $limitBy; if($startNext < ($allPages * $limitBy) and $allEntries > $limitBy) {print "     <b><a href=\"".$PHP_SELF."?limitStart=".$startNext."\">next</a></b> ";} } ?> <?php if(!isset($limitStart)){$limitStart = 0;} showPageNavigation(130,$limitStart,20); ?>