Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Display array, or dir read in rows of five ?

    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 !

  • #2
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    AND THE ANSWER WAS....


    PHP Code:

    <?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";
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •