View Full Version : Output Data to table (need column help)

03-08-2008, 03:07 AM
Hey there, need some help here.. im stuck

What I have is a for loop that goes through and outputs an ip address to a table cell, each recursion creates a new row and prints the address... so basically what im left with is a very long 1x1 table.

now im happy that my code works for generating the table, but what im wondering is, is there a way i can "wrap" the table at the bottom and create a new column when the table reaches the bottom of the screen?

basically turning it into a 1x2 table.. (or 1x3, 1x4, etc)

is this possible?

$infocount = 18;
$timeout = 2;

echo '<table width="500" border="0" align=left>';
for($i=0; $i<=$infocount; $i++){
$fp = @fsockopen ($info[$i]["address"], $info[0]["port"], $errno, $errstr, $timeout);
if ($fp) {
echo "<tr><td width=50><img src='images/up2.gif' alt='Connected'></td><td width=450><a href='http://" . $info[$i]["address"] . "'>" . $info[$i]["name"] . "</a></td></tr>";
echo "<tr><td width=50><img src='images/down2.gif' alt='Down!'></td><td width=450>" . $info[$i]["name"] . "</td></tr>";
echo '</tr></table>';

hope that works... lol... can someone help me get the table to wrap itself to a new column once it starts showing scrollbars?

thanks so much in advance!!

03-08-2008, 03:24 AM
Fumigator helped me with a similar problem before. You need to use the modulus operator (&#37;). I'm not sure if you can create a new row simply when the scrollbars appear, but you can estimate how many cells it takes in order to make them appear.

When you get this number, let's say 10, you need to check the modulus every time the loop runs. divide 10 by the variable $i (in your case). If the mod != 0 then allow the table to create normally, if the mod == 0 then include the html tags to create another column.

You might need to nest your table within another tables' <td> so that other <td>'s in the nesting table can be made.