Display Album with Photos (PHP)

alekksaxx

New Member
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.I have 2 tables, 'Photo' and 'Album'.\[code\]Album columns : ID TITLE USER_ID CREATED MODIFIEDPhoto columns : ID ALBUM_ID TITLE LOC CREATED MODIFIED\[/code\]I'm using the query\[code\] $this->db->select('*'); $this->db->from('album'); $this->db->join('photo', 'album.id = photo.album_id'); $this->db->limit(10); return $this->db->get();\[/code\]which I think translates into\[code\]SELECT * FROM album JOIN photo ON album.id = photo.album_id LIMIT 10;\[/code\]Anyways, what I don't understand is how to display each album with the related photos.So something like...\[code\]<div class="album"><img src="http://stackoverflow.com/questions/3757504/image1" /><img src="http://stackoverflow.com/questions/3757504/image2" /></div><div class="album"><img src="http://stackoverflow.com/questions/3757504/image3" /></div>\[/code\]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. Should I even be using a JOIN query?UPDATE: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.
 
Back
Top