You can set the limit several ways.
One way is by setting a limit on your query:
PHP Code:
$query= mysql_query("SELECT * FROM Persons LIMIT 0,100");
while($row = mysql_fetch_array($query))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
Another way is using the for method:
PHP Code:
for($i = 0; ($condition) && $i < 100; $i++){
//process
}
Your method should work fine as well but haven't tested it.