Re: [PHP] Creating 'Next' & 'Previous' for PHP Photo Gallery




Jim,

Code looks extremely promising & well explained - let me give it a try and
work it out. I'm sure to hit snags - but can't thank you enough.

The one thing that comes straight off in my mind looking at the code is -
and I may be addressing this prematurely since I haven't tried the code yet
- but my thumbnails are in a Separate .php page, and each thumbnail links to
the full image which are in a Separate .php page.
The Next & Previous link I'm trying to create are to be displayed on the
full image page.

But let me integrate the code and see how I can pass the values along to
pages and make it work.

Thanks again!


On 7/10/07 11:04 AM, "Jim Lucas" <lists@xxxxxxxxx> wrote:

Rahul Sitaram Johari wrote:
I¹m trying to write a Photo Gallery in PHP. Everything else is pretty much
worked out ­ like thumbnails, indexes, titles & all ­ the one thing I¹m
stuck at is the Next & Previous links for the Photos on the main Photo Page.

It¹s a simple program where you drop images in a folder and glob() picks up
the thumbnails ­ displays them on a page ­ which are automatically linked to
the Full Size Images. This is the code:

<?
$ID = $_GET['ID'];

The following code is completely untested. I typed it straight into the email
client.
You might have to track down a few bugs. It should give you a good start
though

# Set your page display limit
$display_limit = 20;

# Collect a list of files
$filelist = glob("$ID/thumbnails/*.jpg");

# get the current page number, set the default to 1
$pageNum = 1;
if ( !empty($_GET['pageNum']) ) {
$pageNum = (int)$_GET['pageNum'];
}

# count the total number of files to list
$total_files = count($filelist);

# calculate the total number of pages to be displayed
$total_pages = ceil($total_files/$display_limit);

# Initialize the link holder array
$links = array();

# Since I don't know the name of your script, I assume that it should link to
itself
# So I will use $_SERVER['SCRIPT_NAME'] to get the scripts true name

# Create Previous tag is needed
if ( $pageNum > 1 ) {
$links[] = "<a
href='{$_SERVER['SCRIPT_NAME']}?ID={$_GET['ID']}&pageNum=".($pageNum-1)."'>Pre
vious</a>";
}

# Create Next tag is needed
if ( $pageNum < $total_pages ) {
$links[] = "<a
href='{$_SERVER['SCRIPT_NAME']}?ID={$_GET['ID']}&pageNum=".($pageNum+1)."'>Nex
t</a>";
}

# Display the link if they exist
echo '[ '.join(' | ', $links).' ]';

foreach ($filelist as $key=>$value) {

$title = rtrim(basename($value),'.jpg');
$newtitle = preg_replace('/_/', ' ', $title);
?>
<A HREF="photo.php?photo=<?php echo basename($value); ?>&title=<?php echo
$newtitle; ?>&ID=<?php echo $_GET['ID']; ?>&KEY=<?php echo $key; ?>"
TARGET="photoFrame">
<IMG SRC="<?php echo $ID; ?>/thumbnails/<?php echo basename($value);
?>"></A>
<?php echo $newtitle; ?>
<?
}
?>

I know that $key holds the sequence of images that are being picked up by
glob() - I¹m just trying to figure out a way to use this $key to generate
the Next & Previous link. The problem is ­ everything is passed on to a
separate page (photo.php) ... What I¹m thinking is determining which Photo
File would be Next or Previous to the one being selected, and passing that
along to the (photo.php) page. I¹m just not able to figure out how to pick
out the next & previous filename and place it in the Query String.

Any suggestions?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rahul Sitaram Johari
CEO, Twenty Four Seventy Nine Inc.

W: http://www.rahulsjohari.com
E: sleepwalker@xxxxxxxxxxxxxxxx

³I morti non sono piu soli ... The dead are no longer lonely²



.



Relevant Pages

  • Re: Display photos in Outlook 2003 e-mail
    ... > When I recieve an e-mail I have to open each photo attached. ... MIME parts with content disposition of "attach"). ... Outlook does NOT have the preview area appended onto the display of a ... message to show graphical images with content disposition "attach" as ...
    (microsoft.public.outlook.general)
  • Re: Switch images at timed interval
    ... I have a page that has a photo in the center and I'd ... Any number of images, random ... display, no repeats per cycle. ... Gecko (because their javascript is demented.) Javascript. ...
    (alt.html)
  • Re: [PHP] Creating Next & Previous for PHP Photo Gallery
    ... Don't try to figure out the name of the photo that is next/previous. ... required to return the files in any particular order, nor does glob ... worked out ­ like thumbnails, indexes, titles & all ­ the one thing ... the Full Size Images. ...
    (php.general)
  • Display Records in certain order (string contained in field)
    ... I have a simple asp page that desplays images from database. ... I display the images with a do loop as follows: ... I want to have the images that have the string 'photo' within the 'TITLE' ...
    (microsoft.public.inetserver.asp.db)
  • Re: Slashdot | NASA BlueMarble: Next Generation
    ... > But the 2km/pixel ones wouldn't display on my work PC. ... IE nor MS Photo ... > Editor would have anything to do with such large images. ...
    (uk.sci.astronomy)