jsschmitt Posted June 18, 2009 Share Posted June 18, 2009 The code I am using automatically builds the list based on a folder and it's contents. The issue is, the current next/prev buttons allow you to go to pages that don't exist. I have poked and proded at the code, but can't figure out what i did wrong... To see the code in action: http://anomymage.com/tests/do/dep/galleries/engagements/index.php This is the code I have: <?php $images = glob('*.jpg'); $images = array_reverse($images); $imageIndex = isset($_REQUEST['index']) ? $_REQUEST['index'] : count($images)-1; echo '<img src="'.$images[$imageIndex].'" width="85%" alt="" /><br/><br/><br/><br/><br/>'; ?> </div> <div id="leftnavgal"> <?php echo '<a href="?index='.($imageIndex+1).'">'; ?> Prev</a> </div> <div id="rightnavgal"> <?php echo '<a href="?index='.($imageIndex-1).'">'; ?> Next</a> </div> </body> </html> Any help? Link to comment https://forums.phpfreaks.com/topic/162811-solved-simple-photo-gallery-next-prev-buttons/ Share on other sites More sharing options...
jsschmitt Posted June 18, 2009 Author Share Posted June 18, 2009 Note: This is for an iPhone/iPod touch based site. Link to comment https://forums.phpfreaks.com/topic/162811-solved-simple-photo-gallery-next-prev-buttons/#findComment-859152 Share on other sites More sharing options...
MatthewJ Posted June 18, 2009 Share Posted June 18, 2009 Wouldn't you need something in there to see if you have reached the maximum array index? Like if index + 1 is greater than count - 1 index = count - 1 Link to comment https://forums.phpfreaks.com/topic/162811-solved-simple-photo-gallery-next-prev-buttons/#findComment-859159 Share on other sites More sharing options...
ldougherty Posted June 18, 2009 Share Posted June 18, 2009 Your code does no checking to see if the image actually exists before displaying the previous/next buttons which is why you can navigate to images that don't exist. Try putting in something that checks to see if the value being processed falls within the index range before showing the navigation buttons. Link to comment https://forums.phpfreaks.com/topic/162811-solved-simple-photo-gallery-next-prev-buttons/#findComment-859185 Share on other sites More sharing options...
jsschmitt Posted June 22, 2009 Author Share Posted June 22, 2009 Solved! Thanks for the poke in the right direction! <div id="leftnavgal"> <?php if (count($images)-1 > $imageIndex){ echo '<a href="?index="'.($imageIndex+1).'">Prev</a>';} else { echo '';}; ?> </div> <div id="rightnavgal"> <?php if ($imageIndex > 0){ echo '<a href="?index='.($imageIndex-1).'">Next</a>';} else { echo '';}; ?> </div> Link to comment https://forums.phpfreaks.com/topic/162811-solved-simple-photo-gallery-next-prev-buttons/#findComment-861391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.