Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2013, 04:39 AM   PM User | #1
Local Hero
New Coder

 
Join Date: May 2005
Location: Utah
Posts: 58
Thanks: 6
Thanked 0 Times in 0 Posts
Local Hero is an unknown quantity at this point
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);  
?>
Local Hero is offline   Reply With Quote
Old 02-18-2013, 02:53 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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>');

__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:01 PM.


Advertisement
Log in to turn off these ads.