...

View Full Version : Display array, or dir read in rows of five ?



Peuplarchie
07-25-2007, 03:14 AM
Good day to you all,
I was wondering how can I display the result of the array of files I have read from a directory.

I know How to read from a directory but I am wondering how to diplay the result in a table with, let's say, rows of 5 images.

What would happen if I don't have enough of file to make a row ?

Thank to you !

Peuplarchie
07-25-2007, 11:48 PM
AND THE ANSWER WAS....





<?php
$image_counter = 3;
$row_counter = 0;
$cell_counter = 0;
$show=array('.jpg','.JPG','.gif','.GIF');
$path = './images/';
$dir_handle = @opendir($path) or die("Unable to open $path");
$image_table = "<table>\n<tr><th colspan=5>Existing Pics in Directory:</th></tr>\n<tr>";
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 2) % 5)){
$row_counter++;
}
$image_table .=(($image_counter + 2) % 5)? "" : "</tr>\n<tr>";
$image_table .= "\n<td><img src=\"$path$file\"><br>$file</td>\n";
++$image_counter;
++$cell_counter;
}

}
$colspan= ($row_counter * 5) - $cell_counter;
$image_table .= ($cell_counter % 5) ? "<td colspan=$colspan>&nbsp;</td>" : "";
$image_table .= "</tr>\n</table>\n";
echo "$image_table<br><br>";
echo "<b>Total Cells w pics: $cell_counter<br>";
echo "<b>Total Rows: $row_counter<br>";
echo "<b>Empty Cells in last row: $colspan";
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum