title: Display Album with Photos (PHP)
body: <p>To start off, this really isn't CodeIgniter specific. I'm having trouble grasping an idea, so anyone that knows PHP/SQL (or whatever my problem is) can jump in.</p>
  
  <p>I have 2 tables, 'Photo' and 'Album'.</p>
  
  <pre><code>Album columns : ID  TITLE  USER_ID  CREATED  MODIFIED
  Photo columns : ID  ALBUM_ID  TITLE  LOC  CREATED  MODIFIED
  </code></pre>
  
  <p>I'm using the query</p>
  
  <pre><code> $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('album');
      $this-&gt;db-&gt;join('photo', 'album.id = photo.album_id');
      $this-&gt;db-&gt;limit(10);
      return $this-&gt;db-&gt;get();
  </code></pre>
  
  <p>which I think translates into</p>
  
  <pre><code>SELECT * FROM album JOIN photo ON album.id = photo.album_id LIMIT 10;
  </code></pre>
  
  <p>Anyways, what I don't understand is how to display each album with the related photos.</p>
  
  <p>So something like...</p>
  
  <pre><code>&lt;div class="album"&gt;
  &lt;img src="image1" /&gt;
  &lt;img src="image2" /&gt;
  &lt;/div&gt;
  &lt;div class="album"&gt;
  &lt;img src="image3" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Basically how do I "echo" out the correct albums and their relative images? As far as I can tell, a foreach loop is just going to write out each image without discriminating between which album the image belongs to. </p>
  
  <p>Should I even be using a JOIN query?</p>
  
  <p>UPDATE:</p>
  
  <p>Wow, ok tilman, you are pro. Thanks a lot for the help. For anyone else referencing this, make sure you change 'id' in $array[$row['id']][] = $row; to whatever your album id is. In my case, its album_id. My final join statement was overwriting id with album_id. </p>