jmansa
February 8, 2010, 4:03pm
1
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
<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>
jmansa
February 8, 2010, 4:28pm
4
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.
jmansa
February 8, 2010, 4:44pm
6
??? 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.
jmansa
February 8, 2010, 4:53pm
8
guido2004:
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