View Single Post
Old 02-08-2008, 07:01 PM   #4 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
An example which uses a directory of images is given below. The folder structure is such that we have an images folder and within that a thumbs folder. Filenames match between the folders representing a thumbnail and full-sized version of the same image. It's up to you to create the thumbnails however you like.

PHP Code:
<?php

include('pagination.php');
$p = (isset($_GET['p']) AND ctype_digit($_GET['p']) AND (int) $_GET['p'] > 0
   ? (int) 
$_GET['p'
   : 
1;
$max 10;

// Create the object and set some basic values.
$pagination = new pagination();
$pagination->setMax($max);

// Set up some directory variables 
$dir    dirname(__FILE__).'/images/';
$webdir 'images/';
$thdir  'images/thumbs/';

// Grab all of the images 
$images glob($dir.'*.jpg');

// Set up pagination variables
$totPages  $pagination->getPages($images);
$first     $pagination->setPage($p);
$page      $pagination->getCurrentPage();

// Only select the portion of the images array 
// that represents our page
$exResults array_slice($images$first$max);

// Make links spaced a bit
echo '
<style type="text/css">
a { margin: 0 2px 0 0; }
</style>'
;

// Start pagination display
printf('Page: %d of %d | '$page[0], $page[1]);
$pagination->checkLink($p 1) AND printf('<a href="?p=%d">Previous Page</a>'$p 1);
foreach (
$totPages as $pageNumber)
{
    
$tpl = ($pageNumber == $p)
         ? 
'<a href="?p=%1$d">%1$d</a>'
         
'<a href="?p=%1$d"><strong>%1$d</strong></a>';
    
printf($tpl$pageNumber);
}
$pagination->checkLink($p 1) AND printf('<a href="?p=%d">Next Page</a>'$p 1);

// Display current page of images 
echo '<hr><div class="images">';
foreach(
$exResults as $image)
{
    
$image str_replace($dir$webdir$image);
    
$thumb str_replace($webdir$thdir$image);
    
printf('<a href="%s" style="margin: 0 5px 5px 0;"><img src="%s" alt="%s"></a>',
           
$image$thumbbasename($image));
}
echo 
'</div>';
It's just a very quick example essentially ported over from the MySQL example posted above. Don't shoot me if it doesn't work!
Thanks
And thanks for moving it

Well, I'm glad that it seems to work without MySQL aswell, because that was my intention, to not just limit the class to a MySQL based pagintion
__________________
Tanax is offline  
Reply With Quote