View Full Version : loop help

03-23-2007, 09:53 PM
I have the below code that is pulling all rows out of table and then listing them in a table. But I only want it to show the first 10 rows only, and not sure how to cap it at 10.

I'm currently using a while loop as follows:
while ($stat = mysql_fetch_array($result))

{ ?>
<tr class="<?php if ($rownum%2) { echo "line_2"; } ?>">
<?php echo number_format(($stat['Rating']), 3); ?>
<td style="text-align:left;">
<a href="index.php?page=profile&pid=<?php echo ($stat['id']); ?>"> <?php echo ($stat['login']); ?></a>
echo "\n";

03-23-2007, 10:00 PM
Include "LIMIT 10" in your query (last line), or use a counter in your loop (a FOR loop works well for this).

03-23-2007, 10:01 PM
Use LIMIT in your mysql query


(not best site, was first on google :s )

03-23-2007, 10:52 PM

Work perfect. I was struggling to get a For loop to work with, and get getting all the rows. But the LIMIT works just as good.