Page 1 of 1

</tr> after 5 results.

Posted: Fri Dec 23, 2005 2:04 am
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>

Posted: Fri Dec 23, 2005 3:45 am
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

Posted: Fri Dec 23, 2005 4:27 am
by Dale
Cheers mac. :)