I have 3 category pages for a photography website that are loaded dynamically from a mysql database, and that works fine, but i would like to add sub-categories or “albums” in each category. This also needs to work dynamically because the website is for someone not technically minded.
So I think I have an idea, just not fully sure how to execute it. In this first block of code is how the images are currently getting loaded (minus a bunch of html gumpf in $dynamicList that isn’t necessary at this stage).
In the second block of code I’ve edited it to be able to load images into separate ‘albums’. However, as it stands, it will load every image into each album.
So is there a way to use “GROUP BY” to load dynamicLists that only contain images that share the same value for the row “album_name” in the database?
Apologies if i haven’t explained myself very well. Any help will be much appreciated.
<?php
include "connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM images WHERE category = 'People' ORDER BY date_added DESC");
while($row = mysql_fetch_array($sql)){
$image = $row["image_name"];
$src_img=imagecreatefromjpeg("photos/thumbs/thumb_".$image);
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<img class="item" src="photos/thumbs/thumb_'.$image.'"/>';
}
mysql_close();
?>
<div id="image_gallery">
<?php echo $dynamicList; ?>
</div>
<?php
include "connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM images WHERE category = 'People' ORDER BY date_added DESC");
while($row = mysql_fetch_array($sql)){
$image = $row["image_name"];
$src_img=imagecreatefromjpeg("photos/thumbs/thumb_".$image);
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<img class="item" src="photos/thumbs/thumb_'.$image.'"/>';
$album = $row["album_name"];
$albumList .= '<div class="album"><div class="album_title"><h2>'.$album.'</h2></div>'.$dynamicList.'</div>';
}
mysql_close();
?>
<div id="image_gallery">
<?php echo $albumList; ?>
</div>
Something like this? (untested)
I don’t think a GROUP BY clause actually helps you, though you could implement a different solution if you knew they were in album order – you’d just have to check for when it transitions the the next album…. well, now that I’m thinking about it, maybe that’s a little simpler…