Standard Many to Many problem: photo can be in many galleries, each gallery has many photos.
Standard solution:
aditional table that forms the matrix of gallery-photo associations
gallery table
gall_id, name, etc
photo table
photo_id, subject, etc
gall_photo table
photo_id, gall_id