Jump to content


This topic is now archived and is closed to further replies.


For Loops

Recommended Posts

right so the thing i want to do is like only show say 30 results then go onto a new page with the other reults.

what i have is:

for ($i=0;$i<$num_rows;$i++)

        echo "<table width=\"729\" height=\"32\" border=\"1\">
                    <td><span class=\"style6\">$reply_subject</span></td>
                    <td width=153 height=\"28\"><p class=\"style3\">Posted By: $poster_name2($poster_id2)<br>
                      Time Of Post: $post_date2 <br>
                      Post Count: $postcount2 </p>
                    <td width=566>$reply_body</td>

now i know i could use something like

[code]if ($i == 5) { break; }[/code]

but someone told me that isnt the best way to do it, and it also wont show like Page 1 - 2 - 3 - 4 etc ate the bottom. any advice on how to improve it would be great.

Share this post

Link to post
Share on other sites
Add to you query (in the end) "LIMIT 30"- To limit the result to 30 rows.
Query for example: "SELECT * FROM `table` LIMIT 30". This will select the 30 first records.
But you can break it in an "ugly" way, adding in the end of the loop:
But using the limit will be better.

For page splitting- just google. Here's an example:
[a href=\"http://www.php-mysql-tutorial.com/php-mysql-paging.php\" target=\"_blank\"]http://www.php-mysql-tutorial.com/php-mysql-paging.php[/a]


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.