I have these two tables:
Galleries - {id,title,description}
Images - {id,gallery_id,file}
Each gallery has multiple images in the images table.
How is it best to approach this:
A. Select all galleries than run a for-loop and for each re-query the database for each image that pertains to it.
$sql='select * from galeries';
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{
$sql2='select * from images where gallery_id='.$row['id'];
//etc
}
B. Select all galeries and images using a left join thus getting gallery information mutiple times, as many times as a gallery has images.
$sql='select * from galleries left join images on galleries.id=images.gallery_id';`
Or is there a better way? Thank you.