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
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    65
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Return results into a table

    I have a folder that has a bunch of images. Then I have a script to view the images of that folder, it puts the images one by one on top of each other along with details about the image. I'd like to put the images into tables and have 2 or 3 images per row. I'm not sure how to do that?

    PHP Code:
    <?PHP
    $handle
    =opendir("./savedImage/");  
    $aFiles = array();  
                      {  
    while ((
    $file readdir($handle))!==false)  
    {   
     
    $aFiles[$file] = filectime('./savedImage/' $file);  
    }  
    asort($aFiles);    
    foreach(
    $aFiles as $key => $value){ 

        echo( 
    $key " - " date("F d Y ."$value). "<a href='savedImage/".$key."' target='blank'><img src=./savedImage/" $key " width=300></a><br><br><hr>");   
        }  
        }  
        }  
        
    closedir($handle);  
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You use modulus and some switching logic. There are several different ways to get there, here is one:
    PHP Code:
    $iNumPerRow 3;
    if (
    count($aFiles) > 0)
    {
        print(
    '<table border="1">');
        print(
    '<tr>');
        for (
    $i 0$value current($aFiles); next($aFiles), ++$i)
        {
            
    $key key($aFiles);
            if (
    $i && ($i $iNumPerRow == 0))
            {
                print(
    '</tr><tr>');
            }
            
    printf('<td>%s - %s.<a href="savedImage/%s" target="blank"><img src="savedImages/%s" width="300"/></a></td>',
                
    $keydate('F d Y'$value), $key$key);  
        }
        print(
    '</tr>');
        print(
    '</table>');

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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