Iba a suponer que esto era una broma... pero veo que no...
mira:
Código PHP:
<?php
$num = 31;
$columnas = 3;
$filas = $num/$columnas;
$html = '<table>';
for($i=0;$i<$filas;$i++){
$html .= '
<tr><!--Fila'.$i.'-->';
for($j=0;$j<$columnas;$j++){
$html .= '
<td>';
if(($i+$tot+$j+1)<=$num){
$html .= ($i+$tot+$j+1);
}
$html .= '</td>';
}
$tot = $j + $tot - 1;
$html .= '
</tr>';
}
$html.= '
</table>';
print $html;
?>
Creo que debes intentar agregarle cosas para poder ir entendiendo y no quedandote con mas dudas.
Suerte!