Zend - The PHP Company




Menus & Navigation

Add Code


Navigation through a page-list  

Type: code fragment
Added by: klbecke
Entered: 04/12/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 8139
Function, which automaticly prints a page-navigation, when there are more entries which are returned from dabase then should be printed on a page


<?php 

//*******************************************************************************
//
//    Klaus Becker, 
//    kbecker@mbo-verlag.de
//    Dezember 2000
//
//    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>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>&nbsp;";
        for(
$entryNr=1$entryNr<=$allPages$entryNr++)
            {
            
$startPage = ($entryNr $limitBy) - $limitBy;
            if(
$thisPage!=$entryNr){print "<b><a href="".$PHP_SELF."?limitStart=".$startPage."">".$entryNr."</a></b>&nbsp;";}
            else{print 
"<b>".$entryNr."</b>&nbsp;";} 
            }
        }
    
$startNext $thisPage $limitBy;
    if(
$startNext < ($allPages $limitBy) and $allEntries $limitBy
        {print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="".$PHP_SELF."?limitStart=".$startNext."">next</a></b>&nbsp;";}
    }
?>





<?php
    
if(!isset($limitStart)){$limitStart 0;}
    
showPageNavigation(130,$limitStart,20);
?>


Usage Example




Rate This Script





Search



This Category All Categories