Jump to content


For Loops

  • Please log in to reply
1 reply to this topic

#1 supanoob

  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 22 June 2006 - 04:36 PM

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

if ($i == 5) { break; }

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.

#2 Orio

  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 22 June 2006 - 04:44 PM

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]

Think you're smarty?

(Gone until 20 to November)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users