</tr> after 5 results.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

</tr> after 5 results.

Post by Dale »

Right, loops are starting to tick me off ... probably because it's like only 8am. But how do I get it to show 5 results then show another 5 below and so on?

I'm using this as my query thing -->

Code: Select all

<?php
$sql = "SELECT * FROM members";
$result = mysql_query($sql, $conn) or die(mysql_error());

while($r = mysql_fetch_array($result)){

}
?>
Where abouts would I stick the loop information if I want my result sto show like this:

Code: Select all

<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could add a count to the while loop so that you know when to start a new row:

Code: Select all

$i = 1;

while ($row = mysql_fetch_assoc($result)) {
    // you can determine whether this is a fifth row using the modulus operator
    $new_row = ($i % 5 == 0) ? true : false;

    // code to create your table cell - if $new_row == true then you
    // can end the previous row and start a new one here

    $i++;
}
You'll have to do a bit of work with the code but hopefully this will give you a starting point.

Mac
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Cheers mac. :)
Post Reply