Jump to content


Photo

Determining Image Gallery Page Number from Image Number


  • Please log in to reply
3 replies to this topic

#1 larstheimpalor

larstheimpalor
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 May 2006 - 05:08 PM

ok i wrote myself a decent photo gallery script that is coming along just fine. i have it setup so that it looks at a folder and grabs all the images files placing them in an array. the columns and rows of images are set by variables.

so say i have 12 images total and set the number of columns and rows to 2. now i have a 3 pages with 4 images each. now in my script once you click on any image it goes to a single image viewer. when you click the image again it goes back to the gallery. my problem is that i would like it to go back to the particular page that image is displayed on.

the numbers of images, rows, and columns can all vary so i need a calculation or function that will determine which page that image is from based souly on it's number in the array.

#2 ShiVer

ShiVer
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationJoMo

Posted 24 May 2006 - 06:04 PM

Could you possibly put the image in a popup window then when they click on the image it just closes the window?

Or if I read right could you try placing a javascript:go.history(-1) on the image so that is just goes back in history when clicked?

#3 larstheimpalor

larstheimpalor
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 May 2006 - 06:47 PM

thanks, ShiVer, for the workarounds but i know there is a simple way to do this in an equation or if/then statement.

and the reason i wouldn't want to use either of those is that these scripts will be included into other pages and need to be self contained. (i despise popups) also if the user decides to click to the next/previous image in the single image viewer then they would have to hit BACK however many times they clicked, so they might as well use their browser's own back button.



#4 larstheimpalor

larstheimpalor
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 May 2006 - 05:17 PM

take into consideration that my array starts with zero and not one

//should be fairly obvious

$images_per_page = $this->image_num;

//count the image array, divide by the # of images per page and round up

$total_pages = ceil( count($this->gallery) / $images_per_page );

// if the image's id # is less than the # of images per page set to first page

if ($this->x <= $images_per_page) {

    $page = 1;

// else if the image's id # is greater than the number of images per page take the # of times it takes the # of images per page added to itself to be greater than the image id # and set the page to that

} else if ($this->x > $images_per_page) {

    for($page = 1; $this->x > $images_per_page; $page++) {

        $images_per_page = $images_per_page + $images_per_page;

    }
}

i think it's sloppy and probably over coded. all of my code is scripted to work with the array starting with 0. i tried to change that and got all confused and it borked on me. so i left it the way it was.

if anyone has any constructive suggestions/criticism feel free to chime in. i'm just getting used to programming with php classes. it is pretty cool.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users