Stop after number

the problem with my script is when it gets to the end number i.e 13 it then starts all over again from 1. how do i stop it at the end number i.e. 13.


<table width="700" cellpadding="0" cellspacing="0" border="0">
          	<?php
          	include ("connect.php");
    $result = mysql_query("select * from table WHERE visible='yes' ORDER BY sequence ASC");
          	    $counts = mysql_num_rows($result);
          		
          		
          		$count = 1;
          	    while($r=mysql_fetch_array($result)){
          		   $category=$r["category"];
          		   $imghome=$r["imghome"];
          		   $sequence=$r['sequence'];
          		   $catid=$r["catid"];
          	?>
        <? for($i = 1; $i <=$counts; $i++){ ?>
          		<td width="200" align="left">
          			<? if($counts  = $counts){?>
          			<?}else{?>
          			flashtitle<?=$i?><br>
          			<?}?>
          		</td>
                    <?php
                    if ($count == 3) {
                      echo "</tr>
<tr>
";
          			    $count = 0;    
          			          }
          			    $count++;
          			}
                    ?>
          		  <?}?>
              </tr>
          </table>