Forum Moderators: coopster

Message Too Old, No Replies

display a table from scandir array?

         

crackpipe

6:23 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



I have a directory with about 5 files in it.
<?php 
$result = scandir(".");
print_r($result); ?>

The above code of course shows the five files. I want to do them in a three column table. I thought I had it, but the code below simply creates a table with infinite rows.


<html>
<body>
<table border="1" width="100%">
<tbody>
<?php
while ($result = scandir(".")) {
echo "<tr><td> ".$result{'Array'}."</td>
<td>".$result{'Array'}."</td>
<td>".$result{'Array'}."</td></tr>";
}
?>
</tbody></table>
</body></html>

Any suggestions about what is going on? I've also tried it this way, again with infinite rows as result:

<?php
while ($result = scandir(".")) {
echo "<tr><td> ".$result."</td>
<td>".$result."</td>
<td>".$result."</td></tr>";
}
?>

Thanks.

IanKelley

8:39 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Instead of a while loop, read the results into an array ($res = scandir('.');) and then run $res through a foreach loop.

[edited by: eelixduppy at 3:58 pm (utc) on Sep. 6, 2009]
[edit reason] disabled smileys [/edit]