CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Return results into a table (http://www.codingforums.com/showthread.php?t=287813)

Local Hero 02-18-2013 04:39 AM

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


Fou-Lu 02-18-2013 02:53 PM

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>');




All times are GMT +1. The time now is 09:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.