Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-23-2007, 08:53 PM   PM User | #1
ptmuldoon
Regular Coder

 
Join Date: Feb 2005
Posts: 659
Thanks: 5
Thanked 14 Times in 14 Posts
ptmuldoon is on a distinguished road
loop help

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 Code:
<?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";
            } 
        
?>
ptmuldoon is offline   Reply With Quote
Old 03-23-2007, 09:00 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Include "LIMIT 10" in your query (last line), or use a counter in your loop (a FOR loop works well for this).
__________________
Fumigator is offline   Reply With Quote
Old 03-23-2007, 09:01 PM   PM User | #3
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Use LIMIT in your mysql query

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

(not best site, was first on google :s )
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 03-23-2007, 09:52 PM   PM User | #4
ptmuldoon
Regular Coder

 
Join Date: Feb 2005
Posts: 659
Thanks: 5
Thanked 14 Times in 14 Posts
ptmuldoon is on a distinguished road
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.
ptmuldoon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:39 AM.


Advertisement
Log in to turn off these ads.