Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/149829-solved-files-from-folder-to-array/
Share on other sites

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  ???

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.

 

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.