php_beginner_83 Posted April 29, 2009 Share Posted April 29, 2009 Hi All Can anyone help me with this..please. I'm still pretty new to PHP and am slowly figuring it out. I have a photo gallery, that you can navigate through the pics to view each one using 'Next' and 'Previous' links. I want to include this in a website I'm creating. On the website's main page I have a menu. On the menu is the option to select 'Photos'. When you select this, the file that creates the photo gallery is included. However, when I click the 'Next' link to move through the photos, it disappears. Can anyone explain to me why this happens and how I can fix it. Thanks much. My website code is.... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="sclMenu.js"></script> <style type="text/css"> // css styles here </style> </head> <body bgcolor="#000000"> <div id="header"> <img src="Banner_USA.jpg" alt="header image"> </div> <div id="menuNav" > <ul id="dd"> <li><a href="#" class="menu" id="mmenu1" onmouseover="mopen(1);" onmouseout="mclosetime();">Home</a> <div class="submenu" id="menu1" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> <a href="menu_2.php?page=main">Sights</a> <a href="menu_2.php?page=photo">Photos</a> <a href="#">Test 3</a> <a href="#">Test 4</a> </div> </li> <li><a href="#" class="menu" id="mmenu2" onmouseover="mopen(2);" onmouseout="mclosetime();">New York</a> <div class="submenu" id="menu2" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> </div> </li> <li><a href="#" class="menu">Memphis</a></li> <li><a href="#" class="menu">Nashville</a></li> <li><a href="#" class="menu" id="mmenu3" onmouseover="mopen(3);" onmouseout="mclosetime();">San Francisco</a> <div class="submenu" id="menu3" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> <a href="#">Office</a> <a href="#">Sales</a> <a href="#">Customer Service</a> <a href="#">Shipping</a> </div> </li> </ul> </div> <div id="content"> <?php // you build an array for the pages you have. $index = array( "main" => "Sights_text.php" , "photo" => "My_Try_At_Album.php" ); if ( !empty( $_GET["page"] ) ) { $page = $_GET["page"]; if ( array_key_exists( $page , $index ) ) include( $index[$page] ); } ?> </div> </body> </html> And the code for my photo gallery is... <?php // directory where photos are kept $directory = 'images/thumbnails/'; $photos = array(); if($handle = opendir($directory)) { while(false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." ) { $photos[] = $file; } } closedir($handle); } $imgIndex = $_GET['img']; if(!isset($photos[$imgIndex])) { $imgIndex = 0; } $currentImage = $photos[$imgIndex]; if ($imgIndex<=0) { $prev = "Previous"; } else { $prev = "<a href=\"".$_SERVER[php_SELF]."?img=".($imgIndex-1)."\">Previous</a>"; } if ($imgIndex>=(count($photos)-1)) { $next = "Next"; } else { $next = "<a href=\"".$_SERVER[php_SELF]."?img=".($imgIndex+1)."\">Next</a>"; } ?> <html> <body> <?php echo "$prev $next<br>"; echo "<img src=\"{$directory}/{$currentImage}\">"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/156130-using-includemy-pics-disappear-when-trying-to-view-them/ Share on other sites More sharing options...
ignace Posted April 29, 2009 Share Posted April 29, 2009 Read this tutorial: http://www.phpfreaks.com/tutorial/basic-pagination It tells you how you can properly add pagination. This also works for galleries. Quote Link to comment https://forums.phpfreaks.com/topic/156130-using-includemy-pics-disappear-when-trying-to-view-them/#findComment-821871 Share on other sites More sharing options...
php_beginner_83 Posted April 29, 2009 Author Share Posted April 29, 2009 I read that tutorial and it doesn't really help me. It gives an example and talks through it but that's it and I seem to be doing something pretty similar. I need help with my code. Can you see anything that's wrong with it. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/156130-using-includemy-pics-disappear-when-trying-to-view-them/#findComment-821889 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.