title: Creating dynamic categories & sub-categories with mysql queries
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>Apologies if i haven't explained myself very well. Any help will be much appreciated.</p>
  
  <pre><code>&lt;?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 .= '&lt;img class="item" src="photos/thumbs/thumb_'.$image.'"/&gt;';
      }
  mysql_close();
  ?&gt;
  &lt;div id="image_gallery"&gt;
  &lt;?php echo $dynamicList; ?&gt;
  &lt;/div&gt;
  
  
  
  
  
  &lt;?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 .= '&lt;img class="item" src="photos/thumbs/thumb_'.$image.'"/&gt;';
  
          $album = $row["album_name"];
          $albumList .= '&lt;div class="album"&gt;&lt;div class="album_title"&gt;&lt;h2&gt;'.$album.'&lt;/h2&gt;&lt;/div&gt;'.$dynamicList.'&lt;/div&gt;';
      }
  mysql_close();
  ?&gt;
  &lt;div id="image_gallery"&gt;
  &lt;?php echo $albumList; ?&gt;
  &lt;/div&gt;
  </code></pre>