ptmuldoon
03-04-2008, 10:59 PM
I'm looping through a list of players, and checking an 'active' field for each player. And then I want to limit/stop the loop to give me the the first 10 rows.
Unfortunately, I can't simply limit the query, as the 'active' field is not a stored field in the database, but being added to the array later on.
Currently, the code below is giving me all the players with 1 or more active games, when I'd like to limit it 10. I'm not sure, but maybe change the if statement to a do.while loop?
<?
for($i=0; $i < mysql_num_rows($result); $i++){
if($stats[$i]['active'] > 1) {
?>
<tr class="<?php if ($rownum%2) { echo "line_2"; } ?>">
<td>
<?php echo number_format($stats[$i]['Rating'], 3); ?>
</td>
<td style="text-align:left;">
<a href="index.php?page=profile&pid=<?php echo ($stat['id']); ?>"> <?php echo $stats[$i]['login']; ?></a>
</td>
<td>
<?php echo number_format($stats[$i]['active']); ?>
</td>
</tr>
<? }
} ?>
Unfortunately, I can't simply limit the query, as the 'active' field is not a stored field in the database, but being added to the array later on.
Currently, the code below is giving me all the players with 1 or more active games, when I'd like to limit it 10. I'm not sure, but maybe change the if statement to a do.while loop?
<?
for($i=0; $i < mysql_num_rows($result); $i++){
if($stats[$i]['active'] > 1) {
?>
<tr class="<?php if ($rownum%2) { echo "line_2"; } ?>">
<td>
<?php echo number_format($stats[$i]['Rating'], 3); ?>
</td>
<td style="text-align:left;">
<a href="index.php?page=profile&pid=<?php echo ($stat['id']); ?>"> <?php echo $stats[$i]['login']; ?></a>
</td>
<td>
<?php echo number_format($stats[$i]['active']); ?>
</td>
</tr>
<? }
} ?>