Dynamically creating a horizontal table with vertical columns

Blimey, I never thought this would be so difficult, but I just cant sem to get the order of it all right.

I need a horizontal table to be created where the title of category sits at the top of each column, and then the documents associated with them order up below.

I have been around in circles with it, and wondered if someone can help me with this.

What does need to happen though is that the table is whole from top to bottom, as in if one column only has say 2 documents to show, and next column has 10 then basically 10 rows are created to fill out the table, and not 2 rows in one column and 10 in the next.

This is what I got, and its clse but basically not good enough.


<table width="100%">
<tbody>
<?php
$t=mysql_query("select * from Categories WHERE (Active=1) ORDER BY ID");
while($g=mysql_fetch_assoc($t)){ ?>
<tr>
<th><?php echo $g['Name']?></th>
</tr>
<tr>
<td style="background-color:#CCCCCC;">
<?php $k=mysql_query("select * from Documents WHERE (Active='1') AND (Category=$g[ID]) AND (User=$cID) AND (Corporation=$CORPid) ORDER BY ID");
while($d=mysql_fetch_assoc($k)){ ?> 
<h3 style="float:left; display:inline-block; color:#FFFFFF; line-height:22px;"><a href="index.php?corpID=<?php echo $CORPid?>&pdf=<?php echo $d['ID']?>#topB" title="Description" style=" text-decoration:underline; text-transform:uppercase; color:#333;"><?php echo $d['Title']?></a> |&nbsp;</h3>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>


This sort of gets me a part of the way


<table border="1">
<tr>
<?php
$t=mysql_query("select * from Categories WHERE (Active=1) ORDER BY ID");
while($g=mysql_fetch_assoc($t)){ ?>
<th><?php echo $g['Name']?></th>
<?php } ?>
</tr>
<tr>
<?php ?>
<td></td>
<?php ?>
</tr> 
</table>

But once I try and get the content out, it falls appart, and also I need it to have a complete rown and column look toit, so even if there one bit of data in a column 5 colums down, it creates a row across the line.

Nearly, but again not right:


<table border="1">
<tr>
<?php
$t=mysql_query("select * from Categories WHERE (Active=1) ORDER BY ID");
while($g=mysql_fetch_assoc($t)){ ?>
<th><a href="#" title="<?php echo $g['Name']?> - Click to view all documents"><?php echo $g['Name']?></a></th>
</tr>
<tr>
<?php $k=mysql_query("select * from Documents WHERE (Active='1') AND (Category=$g[ID]) AND (User=$cID) AND (Corporation=$CORPid) ORDER BY ID");
while($d=mysql_fetch_assoc($k)){ ?> 
<td><?php echo $d['Title']?></td>
<?php } ?>
<?php } ?>
</tr> 
</table>


Thinking that I just get them to output right before moving on.

The first column works here, but the other categories then fall below that rather than running horizontally.

Maybe try CSS here rather than looping through many times

transform:rotate(270deg);

Untested, you may have to turn the text as well

Hi,

I have never come across that before in honesty.

have you got an example i could play with.

I don’t. I’m not really a CSS guy anymore, I am playing around with it right now though.

Ok I think I will need to stick with php if i can, as that may take some time, and also may have older browser issues, and cant take the risk of it not working, as deadline very tight.

Thanks though, and if you get it working, post it as an aswer to a problem in the css forum, so we can all have a look.

Understand that to properly do what you want in PHP you have to loop through each row, for each column. The pseudo code would be something like this:


print "<table>\
";
foreach($headers as $header) {
    print "<tr>\
";
    print "<td class=\\"header\\">$header</td>\
";
    foreach($resultSet as $row) {
        print "<td>" . $row[$header] . "</td>\
";
    }
    print "</tr>\
";
}
print "</table>";