Código PHP:
<?php
include("php/config.php");
$columnas="3"; // aca le decis cuantas columnas queres que tenga
$query = "SELECT * FROM trabajos ORDER BY idfoto ASC";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
?>
<table width="100%" border="1" style="border-collapse:collapse;" bordercolor="#000000">
<?php
while(list($idfoto, $nombre) = mysql_fetch_array($result))
{ ?>
<tr>
<?php $col="0"; do{ ?>
<td><div align="center" style="width:300px; margin:20px; background-color: #005353"><div align="left" style="width:300px; background-color:#003333; margin-bottom:5px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFFFFF"><?php echo "$nombre";?></div>
<a href="php/detalle_todo.php?idfoto=<?=$idfoto;?>"><img src="php/download.php?idfoto=<?=$idfoto;?>" border="2"><?=$thumb;?></a><div style="width:300px; height:5px; background-color:#003333; margin-top:5px;"></div></div> </td>
<?php $col++; }while($col < $columnas); ?>
</tr>
<?php
} ?>
</table>
<?php
} ?>