SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
    <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>

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This sort of gets me a part of the way

    Code:
    <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.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nearly, but again not right:

    Code:
    <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.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Maybe try CSS here rather than looping through many times

    Code:
    transform:rotate(270deg);
    Untested, you may have to turn the text as well

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have never come across that before in honesty.

    have you got an example i could play with.

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    I don't. I'm not really a CSS guy anymore, I am playing around with it right now though.

    Quote Originally Posted by multichild View Post
    Hi,

    I have never come across that before in honesty.

    have you got an example i could play with.

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by multichild View Post
    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:

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •