Codice PHP:
$sql "SELECT gallery.nomeGallery, gallery_foto.nomeMin, gallery_foto.idFoto FROM gallery_foto INNER JOIN gallery ON gallery_foto.idGallery = gallery.idGallery ORDER BY gallery.nomeGallery;";
$risultato mysql_query($sql$con); 
echo 
"<table width='100%' border='1'>";
$column 1;
while(
$riga mysql_fetch_object($risultato)) { 
    if (
$column == 1) {
        echo 
"<tr>";
    }
    echo 
"<td>[img]".$riga->nomeMin."[/img]</td>";
    if (
$column == 5) {
        echo 
"</tr>";
        
$column 1;
    } else {
        
$column++;
    }
}
if (
$column != 1) {
    echo 
"</tr>";
}
echo 
"</table>"