$cont=1;while($categres=mysql_fetch_assoc($result3)){ echo "<td>"; echo $categres["nombre_del_campo"]; echo "</td>"; if($cont==4) { echo "</tr><tr>"; $cont=0; } else { $cont++; }}