rvdb86 Posted March 17, 2009 Share Posted March 17, 2009 Hey hope someone can help me. I am trying to make a photogallery from files in a folder. using the following code i have managed to display all the photos in the folder and show them in a table 3 columns wide by x number of rows: $query_galleryname = "SELECT gallery_name FROM ".SITE_Name."_galleries WHERE gallery_id = '".$_GET['view']."'"; $result_galleryname = mysql_query($query_galleryname) or die ("Couldn't execute query"); while ($row_galleryname = mysql_fetch_array($result_galleryname)) { extract($row_galleryname); echo "<tr>"; echo "<td colspan=\"3\"><h1>".$gallery_name."</h1></td>"; echo "</tr>"; } $dir = "galleries/".$_GET['view']."/thumbs"; $dh = opendir($dir); $i = 0; $max_columns = 3; while (($file = readdir($dh)) !== false) { if (!is_dir($file)){ // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid file if($file != "" && $file != null) //echo "<td>$template_name</td>"; ?> <td class="pics" width="170"><a href="galleries.php?view=<?php echo $_GET['view']; ?>&pic=<?php echo $file; ?>"><img src="galleries/<?php echo $_GET['view']; ?>/thumbs/<?php echo $file; ?>" width="160" height="105" border="0"></a> <?php // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // close if dir check closedir($dh); // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> when the user clicks on a picture it shows the picture by itself. i want to create a previous and next button and i am not sure how to do this. I am prety sure i need an array (but i have a fear of arrays) and how would i find the position of the current picture in the array? I really hope someone can help me out! TIA Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/ Share on other sites More sharing options...
jlhaslip Posted March 17, 2009 Share Posted March 17, 2009 Look for a pagination script. Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/#findComment-786795 Share on other sites More sharing options...
rvdb86 Posted March 17, 2009 Author Share Posted March 17, 2009 hi jlhaslip, i am not looking to paginat the results. when the user clicks on one othe thumbnails which has the url galleries.php?view=GALLERYID&pic=PICTURE FILE NAME and it shows the individual picture from the path galleries/$_GET['view']/$_GET['pic'] the problem with this is that they cannot go foward or backwards through the pictures in the folder. I think i need to put all the files into an array and then somehow find out what the position of the current file is in the array and use this as navigation through the files i just dont know how to do this ??? Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/#findComment-786810 Share on other sites More sharing options...
syed Posted March 17, 2009 Share Posted March 17, 2009 Place all images in an array. When you click the image, add ImageID to the querystring and place the selected image id in the querystring. Example galleries.php?view=GALLERYID&pic=PICTURE FILE NAME&ImageID= $imageId; In your galleries.php rebuild the array of images. To visit the next page, Increment the ImageID variable. and place the new ImageID in the next button. Do the same for previous button by subtracting from the ImageID variable. Example if (($ImageID > 0) AND ($ImageID < count($ImageArray))){ $previous = $ImageID--; $next = $ImageID++ } <a href=\"galleries.php?view=GALLERYID&pic=PICTURE FILE NAME&ImageID= " . $previous . "\">PREVIOUS</a> <a href=\"galleries.php?view=GALLERYID&pic=PICTURE FILE NAME&ImageID= " . $next . "\">NEXT</a> Something like the above, there are a few ways to do this. Not tested code. Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/#findComment-786825 Share on other sites More sharing options...
rvdb86 Posted March 17, 2009 Author Share Posted March 17, 2009 wow syed thanks for the help works perfectly!! Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/#findComment-786843 Share on other sites More sharing options...
syed Posted March 17, 2009 Share Posted March 17, 2009 I'm glad it word rvdb86 Quote Link to comment https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/#findComment-786923 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.