Escape after 3 turns during turning query

The code below produces the result below

[b]code[/b]

$test=mysql_query(" 
select name
from myTable
limit 5
") ;

echo "[COLOR="Blue"]start[/COLOR]";
while( $row = mysql_fetch_array($test)  )
{
echo $row['name']."<br>";
}
echo "[COLOR="blue"]end[/COLOR]";

[b]result[/b]

[COLOR="Blue"]start[/COLOR]
Tom
Jane
John
Kate
Tim
[COLOR="Blue"]end[/COLOR]

I like to make it to escape after 3 turns.

The would-be code below doesn’t work correctly, but I hope it shows what I want.

[b]would-be code[/b]


$test=mysql_query(" 
select name
from myTable
limit 5
") ;

$i=1;
echo "[COLOR="Blue"]start[/COLOR]";
while( $row = mysql_fetch_array($test)  )
{
echo $row['name']."<br>";
if ($i==[COLOR="red"]3[/COLOR])
{ [COLOR="red"]escape()[/COLOR] }

$i=$i+1;

}
echo "[COLOR="blue"]end[/COLOR]";

[b]target result[/b]

[COLOR="blue"]start[/COLOR]
Tom
Jane
John
[COLOR="Blue"]end[/COLOR]


First of all, why not just change the limit?

But, regardless, here’s my suggestion:

$NameQuery = MySQL_Query('
SELECT
    name
FROM
    myTable
LIMIT 5
');

echo 'start';
echo '<ul>';
for(
    $i = 0, $row = MySQL_Fetch_Assoc($NameQuery);
    $i < 3 && $row !== false;
    $i++, $row = MySQL_Fetch_Assoc($NameQuery)
){
    echo '<li>' , $row['name'] , '</li>';
}
echo '</ul>';
echo 'end';

If you want to leave the loop after n-times, you use a counter variable and php’s break; statement, however I agree with Jake - why not just change the limit?