Jump to content

Determining Image Gallery Page Number from Image Number


larstheimpalor

Recommended Posts

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

[code]
//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;

    }
}
[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.