Jump to content

For Loops


supanoob

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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.