Jump to content

Archived

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

supanoob

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:
[code]
$num_rows=mysql_num_rows($result3);


for ($i=0;$i<$num_rows;$i++)
{
$row=mysql_fetch_array($result3);
$poster_name2=($row['poster_name']);
$poster_id2=($row['poster_id']);
$board2=($row['board']);
$post_date2=($row['post_date']);
$reply_to=($row['reply_to']);
$reply_body=($row['reply_body']);
$reply_subject=($row['reply_subject']);


        
        echo "<table width=\"729\" height=\"32\" border=\"1\">
                  <tr>
                    <td><span class=\"style6\">$reply_subject</span></td>
                  </tr>
              
                <br>
                
                   <tr>
                    <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>
                    <td width=566>$reply_body</td>
                  </tr>
                </table>";
                }
                ?>[/code]

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:
if($i==30){$i=$num_rows;};
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]

Orio.

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.