Kolinski Posted April 17, 2013 Share Posted April 17, 2013 I have a script that shows 1 thumbnail for every album that has been created. (figure 1.0) I would like to be able to click on the image and be taken to that albums thumbnails. I hope the code underneath is correct. echo '<a href="view_album_front.php?album_id"><img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$dir_arr[$random_key].'" /></a>'; This page of course will use another script similar to the one (figure 1.0) Using the code of test1.php that I have attached. How can I manipulate it to show the thumbnails of a given album id. ?? test1.php Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 17, 2013 Share Posted April 17, 2013 Assuming view_album_front.php is the page for viewing an album, and that it accepts a GET variable of album_id to load the album, just add the album id into the url on line 30: echo '<a href="view_album_front.php?album_id='.$row['album_id'].'"><img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$dir_arr[$random_key].'" /></a>'; Quote Link to comment Share on other sites More sharing options...
Kolinski Posted April 17, 2013 Author Share Posted April 17, 2013 Brilliant thanks for the reply. Now that I can link successfully to the view_album_front.php page. How can I get this page to show the thumbnails of the album? Quote Link to comment Share on other sites More sharing options...
Solution lemmin Posted April 17, 2013 Solution Share Posted April 17, 2013 The same way you show one thumbnail for the album: include 'admin/init.php'; $result = mysql_query("SELECT * FROM albums WHERE album_id = ".$_GET['album_id']); while($row = mysql_fetch_array($result)) { $dir = 'admin/uploads/thumbs/'.$row[0].''; unset($dir_arr); $dir_arr = ""; // Open the directory, echo getting a list of albums if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(get_file_extension($file) == "jpg" || get_file_extension($file) == "png" || get_file_extension($file) == "jpeg") { $dir_arr[] = $file; // puts in array } } closedir($dh); } } //check to see if in an array, if there are any images if(is_array($dir_arr)) { foreach ($dir_arr as $img) { // add a href tag around the image, to view all the thumbnails echo '<img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$img.'" />'; } } else { // If there are no images, what do you want to happen? } } function get_file_extension($file_name) { return substr(strrchr($file_name,'.'),1); } Just loop through the images instead of picking a random one. Quote Link to comment Share on other sites More sharing options...
Kolinski Posted April 17, 2013 Author Share Posted April 17, 2013 I thought I had to foreach it. Wow I can't thank you enough for the help, I've been stuck on it for nearly 2 weeks now. Thank you so much. Just one more question like before we put a a href tag around the thumbnail so we could enter the album how can I do so to view the original sized image ? echo '<a href=""><img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$img.'" /></a>'; Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 17, 2013 Share Posted April 17, 2013 Exactly the same way you display the thumbnail. I don't know where your full size images are, but assuming they are a directory down, it would be like this: echo '<a href="admin/uploads/'.$row['album_id'].'/'.$img.'"><img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$img.'" /></a>'; Quote Link to comment Share on other sites More sharing options...
Kolinski Posted April 17, 2013 Author Share Posted April 17, 2013 Thanks again so much the world needs more people like you Quote Link to comment Share on other sites More sharing options...
Kolinski Posted April 18, 2013 Author Share Posted April 18, 2013 Hello again, If I go back to square one. Test1.php , how can include a line of php to enable the title and description of the album to show on every thumbnail ? the details are kept in the table album ? //check to see if in an array, if there are any images if(is_array($dir_arr)) { // Choose a random image $random_key = array_rand($dir_arr); // add a href tag around the image, to view all the thumbnails echo '<div id="photocontain"><div id="thumbnail"><a class="thickbox" href="view_album_front.php?album_id='.$row['album_id'].'"><img src="admin/uploads/thumbs/'.$row['album_id'].'/'.$dir_arr[$random_key].'" /></a></div></div>'; } else { // If there are no images, what do you want to happen? } } Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 18, 2013 Share Posted April 18, 2013 Assuming the title and description are stored in the database as "title" and "description," you can access the same way you do the album_id: echo '<h2>'.$row['title']</h2><p>'.$row['description'].'</p>'; Quote Link to comment 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.