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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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²
>> 
>> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux