title: creating a photo album gallery
body: <p>I've created a photo gallery where the user can upload images, but I'm  trying to make it where the users can create photo albums to store their images in.</p>
  
  <p>The process works like this. </p>
  
  <ol>
  <li>The User starts by creating an album (the album is stored in the album table like this)</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/yLnqX.png" alt="enter image description here"></p>
  
  <ol start="2">
  <li>Then the user uploads images into the album. (the images are stored
  in the gallery table like this)</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/vvuuY.png" alt="enter image description here"></p>
  
  <p>What I'm trying to accomplish is getting the images to load based on the album they're in. Like this.</p>
  
  <p><img src="https://i.stack.imgur.com/KylYi.png" alt="enter image description here"></p>
  
  <p>So on "Test Album 1" I only want the photos in that album to load and the same with "Test Album 2".</p>
  
  <p>I created an <strong>album.php</strong> page that I want the images to load on based on what album they are in.
  For the two links that are shown in the image, I call them like this. Based off of the albums table.</p>
  
  <p><code>&lt;a href="../gallery/album.php?=&lt;?php echo escape ($ga-&gt;album_id);?&gt;"&gt;</code></p>
  
  <p>Now here is where I'm lacking experience / knowledge. I need to join the two tables together and I can't figure out how to write this query correctly.</p>
  
  <p>I want to query the albums table, album_id and Join it with the gallery table.</p>
  
  <p>Here is the query I have as of now and need help with.</p>
  
  <pre><code>  $gallery = DB::getInstance()-&gt;query("SELECT
  albums.album_id,
  gallery.id,
  gallery.added,
  gallery.album,
  gallery.title,
  gallery.description,
  gallery.file_name
  FROM
  albums
  LEFT JOIN gallery ON albums.album_id = gallery.id WHERE gallery.album = albums.album_id ORDER BY gallery.id DESC LIMIT $start, $limit");
  </code></pre>
  
  <p>Then I call my images like this.</p>
  
  <pre><code>foreach($gallery-&gt;results() as $g){
      ?&gt;
      &lt;li&gt;
      &lt;a class="fancybox" rel="&lt;?php echo escape($g-&gt;album); ?&gt;"
      href="../images/gallery/&lt;?php echo escape($g-&gt;file_name); ?&gt;"&gt;
      &lt;img src="../images/gallery/&lt;?php echo escape($g-&gt;file_name); ?&gt;" class="max-img-border"&gt;&lt;/a&gt;
      &lt;div class="galleryh"&gt;&lt;?php echo escape($g-&gt;title); ?&gt;&lt;/div&gt;
      &lt;div class="galleryp"&gt;&lt;?php echo escape($g-&gt;description); ?&gt;&lt;/div&gt;
  &lt;/li&gt;
  
      &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>If I can just figure out how to write that JOIN query correctly I will be good to go.
  Any solutions would be greatly appreciated.</p>