...

View Full Version : loop help



ptmuldoon
03-23-2007, 08: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:
<?php
while ($stat = mysql_fetch_array($result))

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

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

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

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm

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

ptmuldoon
03-23-2007, 09:52 PM
Thanks

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum