This will do the trick (no tested, written on the fly)
Luis
// column counter
$n = 1;
// start the record
print "<tr>";
foreach($files as $file){
print "<td>$file</td>";
// another column
$n++;
// if 8, then
if ($n==8)
{
// close record, open new, and reset counter
print "</tr><tr>";
$n = 1;
}
}
----- Original Message -----
From: "Peter Houchin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 23, 2003 7:35 AM
Subject: [PHP-WIN] Listing directory files in individual cells in a html
table
> Howdy
>
> I have a script that lists files from a directory. What I want to do is
> spilt the result up so that files are displayed into a html table that
> is 8 colums wide and how ever many rows are needed.
> ( my script is below )
>
> Any help would be aprechiated
>
> Cheers
>
> Peter
>
>
> Heres my script
>
> <table width="92%" border="0" align="center" cellpadding="0"
> cellspacing="1" >
> <?php
> /*
> * This little example prints a sorted directory
> * listing, with dirs first and files afterwards.
> */
>
> // Open current directory
> if($handle = opendir("./images")){
>
> // Loop through all files
> while(false !== ($file = readdir($handle))){
>
> // Ignore hidden files
> if(!preg_match("/^\./", $file)){
>
> // Put dirs in $dirs[] and files in $files[]
> if(is_dir($file)){
> $dirs[] = $file;
> }else{
> $files[] = $file;
> }
> }
> }
>
> // Close directory
> closedir($handle);
>
> // if $dirs[] exists, sort it and print all elements in it.
> if(is_array($dirs)){
> sort($dirs);
> foreach($dirs as $dir){
> # echo "<a href=\"$dir/\">$dir/</a><br />\n";
> echo "";
> }
> }
>
> // if $files[] exists, sort it and print all elements in it.
> if(is_array($files)){
> sort($files);
> foreach($files as $file){
> $ext = strtolower(end(explode('.', $file)));
> if ($ext == 'jpg' ||$ext == 'jpeg' ||$ext == 'png') {
> echo "<tr><td><a href=\"images/$file\" target=\"_blank\"><img
> src=thumb.php?$file></a>\n</td>\n</tr>";
> } else {
> echo "";
> }
> }
> }
> }
> ?>
> </td></tr></table>
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php