$j=0; while($categres=mysql_fetch_assoc($result3)){ for($i=0; $i<4; $i++){ echo categres[$j]; $j++; } echo "<br />"; }