Click to See Complete Forum and Search --> : Help with dynamic data table


Daot Lagorille
11-25-2003, 09:06 AM
Ok:

I have a region on my page that looks like this:

<table border="0" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td>
<?php echo $row_Records['keyid']; ?>
</td>
</tr>
<?php } while ($row_Records = mysql_fetch_assoc $Records)); ?>
</table>
As you can see this automaticall generates one row(tr) with one cell(td) for each record in the query.

What I would like to do is the same thing, except have 5 cells(td) in every row(tr).

I started to do this just using the keyid field in the each record such that if keyid == 1 || keyid == 6 etc..., then it prints a tr, but that sucks and won't work when I have more than one page of records.

Help help.

DaiWelsh
11-25-2003, 09:35 AM
<table border="0" cellpadding="0" cellspacing="0">
<?php
$row =0;
do {
if((($row++) % 5) == 0){echo('<tr>); }
?>
<td>
<?php echo $row_Records['keyid']; ?>
</td>
<?php
if((($row) % 5) == 0){echo('</tr>); }
} while ($row_Records = mysql_fetch_assoc $Records));
if(($row) % 5){
echo('<td colspan="'.(5 - ($row % 5)).'">&nbsp;</td></tr>');
}
?>
</table>

I have not tested it but it should be there or thereabouts.

Daot Lagorille
11-25-2003, 09:57 AM
Not only are you a good person, but you have a good heart. I'll put in a good word with the Lord for you.

THANK YOU!!!