Page 1 of 1

NEED HELP: Multi-Row and Column output

Posted: Sun Dec 15, 2002 2:22 pm
by pb2ya
Ok, I'm writing a script that lets the owner create directories, and can upload as many pictures as they want. The script thumbnails the images and directories. This is the script so far:

Code: Select all

<?php
//include the header
require("include/inc/header.php");
//Create variable path
if (empty($_GET['path']))
{
        $_GET['path'] = "./";
}
$path = $_GET['path'];
//use the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<BR>";
//run the while loop
?><table border=1><tr><?php
while ($file = readdir($dir_handle))
 {
  if(($file != "index.php") && ($file != ".") && ($file != "..") && ($file != "localhost") && ($file != "include"))
  {
   if (is_dir($file))
   {
    echo "<td><a href="?path=$file"><img src="include/images/folder.gif" border="0" height="30" width="30"><br>$file</a></td>";
   }
   else
   {
    echo "<td><a href="$file" target="_blank"><img src=$file><br>$file</a></td>";
   }
  }
 }

//close the directory
closedir($dir_handle);
?></tr></table><?php
//include the footer file
require("include/inc/footer.php");
?>
The issue is, how can I make more than one column output in the table of the images? Can someone give me at least a simple for or while statement that does this, then I would be able to use it in my code.
I also am thinking of next/previous links, but not for now.
Ive tried a lot of stuff on this, someone please just give me some code or a hint.

Posted: Sun Dec 15, 2002 8:12 pm
by LostSoul
pb2ya:

Dump $dir_handle into an array called $file, use count() to get the size of $file:

$fileCount = count($file);

$columnCount = 0;

Setup a for() loop using $fileCount and start echoing data:

<table>
<tr>
for($qw=0;$qw<$fileCount;$qw++)
{
// 4 will be the number of cells across
if($columnCount != '4')
{
echo "<td> DATA </td>";
}
else
{
echo "</tr><tr>";
echo "<td> DATA </td>";
}
$columnCount++;
}
</tr>
</table>


This should give a table with 4 images across before starting a new line. Your next and previous buttons are no problem at this point since you have the array size. Just pass variables for minCount = 10 or something of the sort the tell the for loop where to start in the array and maxCount for when to stop the for loop.

Hope this is helpfull, but as always it's good to find a script that does something similar to what you want and look at the code.