Dynamic Table Columns depending on records?!?

I’m trying to figure this out…

I want to have a 2 column table created dynamicly depending on how many records in my db table…

So if I have 3 records it should look like this:

Test1     Test2
Test3

I’m not quite sure how to do this… Please guide me in the right direction…

Thansk in advance :slight_smile:


<table>
  <tr>
<?php
    $counter = 0; 
    while ($row = mysql_fetch_array($listresult, MYSQL_ASSOC)) {
      echo '<td>' . $row['fieldname'] . '</td>';
      $counter++;
      if ($counter == 2) {
        $counter = 0;
        echo '</tr><tr>';
      }
    }
?>
  </tr>
</table>

Oh yes…Thanks :slight_smile:

1 question though… Is it possible left align first column and right align second column???

I guess so.
Define two classes in your CSS, and then use the counter in the script to decide what class to use.

??? Not sure I understand?!?!

How do you know if the value you’re writing is in the left or right column of the table?
In my script, if $counter = 0, it’s the left column. If $counter = 1, it’s the right column.

Ahh… I see… Thanks. I got it from here :wink: