Write a script 😉
<?PHP
// connect to the database
// query it for the photos
// set a counter
// loop through the result set
// print HTML for the photo
// increment the counter
// see if the counter value is a multiple of 4 and, if so, print HTML to start a new row...