Dynamic Table (colons Depend On The Content Of The Table)
This php code shows me the content of a directory on my website:
Solution 1:
try this:
<?php
$dir = opendir(getcwd());
?>
<body>
<table>
<tbody>
<?php
$n = 0;
while (($file = readdir($dir)) !== false) {
{
if($n%3 == 0){echo "<tr>";}
echo "<td>". $file ."</td>";
$n++;
}
}
closedir($dir);
?>
</tbody>
Solution 2:
you can use modulus to keep track of where you are in the loop. Then, when you've hit a multiplication of 3, you restart the table row:
<?php
$dir = opendir(getcwd());
?>
<body>
<table>
<tbody>
<tr>
<?php
$counter = 0;
while (($file = readdir($dir)) !== false) {
{
if($counter % 3 == 0 && $counter != 0) echo "</tr><tr>";
echo "<td>". $file ."</td>";
$counter++;
}
}
closedir($dir);
?>
</tr>
</tbody>
</table>
</body>
Post a Comment for "Dynamic Table (colons Depend On The Content Of The Table)"