Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
marce23
Forum Newbie
Posts: 11
Joined: Tue Apr 06, 2004 9:35 am

Problem

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
marce23
Forum Newbie
Posts: 11
Joined: Tue Apr 06, 2004 9:35 am

Post 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]
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
Post Reply