Page 1 of 1

Problem

Posted: Wed Apr 07, 2004 2:12 am
by marce23
Hi!
I would like to have 5 pictures in one row...what have i to do???

Code: Select all

<?
    $path = "D:/Programme/Apache Group/Apache2/htdocs/eigeneneu/images/desktop/kleinbild/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {

    $size = filesize($file);
    $size = $size/1024;
    $size = round($size,2);

    if($file == "." || $file == ".." || $file == "index.php" || $file == "index2.php" || $file == "Neu 

Textdokument.txt" || $file == "Thumbs.db" )


        continue;
        echo "
<table align="left">
 <tr>
  <td bgcolor="black" style="BORDER-RIGHT: #3366FF 1px dotted; BORDER-TOP: #3366FF 1px dotted; 

BORDER-LEFT: #3366FF 1px dotted; BORDER-BOTTOM: #3366FF 1px dotted" width="90%">
   <a href="../vollbild/$file" target="_blank" border="0"></a>
   <img src="$file" border="0">
  </td>
 </tr>
 <tr>
  <td bgcolor="black" style="BORDER-RIGHT: #3366FF 1px dotted; BORDER-TOP: #3366FF 1px dotted; 

BORDER-LEFT: #3366FF 1px dotted; BORDER-BOTTOM: #3366FF 1px dotted; text-align: left">Name: $file<br>Size: $size kb
  </td>
 </tr>
</table>
";
    }
    closedir($dir_handle);
?>
thx
marce23

Posted: Wed Apr 07, 2004 2:54 am
by patrikG
Functions will help you execute repetitive tasks while keeping your code somewhat tidy.
Once you've created a function to return a picture, simply call it 5 times.

Posted: Wed Apr 07, 2004 3:00 am
by marce23
@ patrikG:
I wouldn´t have only 1 row with 5 pictures, i would have more rows...
And my question is: What must i do, when i would have a break after 5 images, so the script exports numberofimages/5 rows???
marce23[/quote]

Posted: Wed Apr 07, 2004 3:07 am
by patrikG
Break you code into smaller units, i.e. functions.

One which reads the contents of the directory and returns them.
One which reads the files - one at a time and returns them.
One which generates some HTML and returns it.

And eventually:

one ring to find them and in the webpage, bind them.

Your code becomes clearer, easier to maintain and functions much more smoothly.