$cont=1; while($row=mysql_fetch_array($query)) { echo "<td>"; echo $row["dato a mostrar"]; echo "</td>"; if($cont==5) { echo "</tr>"; echo "<tr>"; $cont=1; } else { $cont=$cont+1; } }