larstheimpalor Posted May 24, 2006 Share Posted May 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10367-determining-image-gallery-page-number-from-image-number/ Share on other sites More sharing options...
ShiVer Posted May 24, 2006 Share Posted May 24, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/10367-determining-image-gallery-page-number-from-image-number/#findComment-38660 Share on other sites More sharing options...
larstheimpalor Posted May 24, 2006 Author Share Posted May 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10367-determining-image-gallery-page-number-from-image-number/#findComment-38676 Share on other sites More sharing options...
larstheimpalor Posted May 30, 2006 Author Share Posted May 30, 2006 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 pageif ($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. Quote Link to comment https://forums.phpfreaks.com/topic/10367-determining-image-gallery-page-number-from-image-number/#findComment-40302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.