VeNoM's WebLog
21 visitor(s) online | 298 visitor(s) in the last 24 hours

  go back

  Buy from my Web Shop

  Baby
  Books
  Camera & Photo
  Classical Music
  Computer & Video Games
  Computers
  DVD
  Electronics
  Jewelry & Watches
  Kitchen & Housewares
  Magazines
  Outdoor Living
  Popular Music
  Software
  Sporting Goods
  Tools & Hardware
  Toys & Games
  Video


  Counter



tutorial, 23/08/2003 09:19

how to add pages to a PHP script ( navigationPages Function )



functions.php
<?
function navigationPages ($total$page$rows$link$pagename='page') {
    
// check for pages
if ($total <= $rows) {
    return 
"";
}

// navigation pages
$pages 3;

// calculate number of pages
$nrpages ceil ($total/$rows);

$min = ($page 1) * $rows 1;
$max $page $rows;
if (
$max $total) {$max $total;}

$inforet "Records ".$min." to ".$max." out of ".$total."
"
;
$inforet .= "Page: ".$page." (".$nrpages.") | ";

for ( 
$i=$i<=$nrpages $i++  {

    if ( 
$i <= $page $pages or $i >= $page $pages ) {
        if ( 
$i == ) {
            
$firstpageret "<a href=\"".$link."&".$pagename."=".$i."\" title=\"First Page\">« First</a> ... ";
        }
         if ( 
$i == $nrpages ) {
         
$lastpageret " ... <a href=\"".$link."&".$pagename."=".$i."\" title=\"Last Page\">Last »</a>";
        }
    }

    if ( 
$page ) {
        
$prevpage $page 1;
        
$prevpageret "<a href=\"".$link."&".$pagename."=".$prevpage."\" title=\"Page ".$prevpage."\">«</a> ";
    }

    if ( 
$i <= $page $pages AND $i >= $page $pages ) {
        if ( 
$page == $i ) {
            
$ret .= " <strong>[".$i."]</strong> ";
        } else {
            
$ret .= " <a href=\"".$link."&".$pagename."=".$i."\" title=\"Page ".$i."\">".$i."</a>";
        }
    }

    if ( 
$page $nrpages ) {
        
$nextpage $page 1;
        
$nextpageret " <a href=\"".$link."&".$pagename."=".$nextpage."\" title=\"Page ".$nextpage."\">»</a>";
    }

}

return 
$inforet.$firstpageret.$prevpageret.$ret.$nextpageret.$lastpageret;

}
? >


testpages.php
<?
include ("functions.php");

// register globals off
$page $_GET['page'];

// check the $page
if (!isset($page) or $page == "" or !is_numeric ($page {$page=1;}

// set the limit for the query
$rows15;

// calculate $min for the limit
$min = ($page 1) * $rows;

// usualy from query
$total 103;

// calculate number of pages
$nrpages ceil ($total/$rows);

// check if $page is valid, again
// this time, compared to $nrpages
if ($page $nrpages or $page 1) {
    
$page 1;
    
$min = ($page 1) * $rows;
}

// query limit
// ... limit $min, $rows

echo "<center>";
echo 
"<a href=\"testpages.phps\">Show source for testpages.php</a>
"
;
echo 
"<a href=\"functions.phps\">Show source for functions.php</a>

"
;
echo 
navigationPages ($total$page$rows"testpages.php?");
echo 
"</center>";
? >


You can view an example here.




If you found this usefull, please consider making a donation.

Contact me if you want a custom script for your website.

Also check out my phpRebel Uploader, an all purpuse file uploader for sale for only 10 USD.