increment an array element to display jpg's ...

This is a discussion on increment an array element to display jpg's ... within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm reading a directory of pictures , and trying to display them nicely formated in a table 4 accross... a ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-01-2004
J Bard
 
Posts: n/a
Default increment an array element to display jpg's ...

I'm reading a directory of pictures , and trying to display them nicely
formated in a table 4 accross...
a few issues ..

My play with array's don't work ...I'm able to feed pictures into array's
,with
$thefiles[$c] = $file;

but when I try to call the pictures
echo "<img src=\"\\images\\$thefiles[$c]\" width='142'height='142'>";
works but

thefiles[$c+1]

bombs ! If I can't manually increment the array I don't see how to do this
..


the whole thing at the moment is:

<html>
<head>
<title>PHP Test</title>
</head>
<body>

<?php

$mydir = dir('images');
?>
<?php $thefiles=array(); ?>
<?php echo '<table border="3">'; $c=0 ?>

<?php

while(($file = $mydir->read()) !== false) {

$c=$c+1 ; // echo $c;
$d=($c+=2);
$thefiles[$c] = $file;


echo '<tr>';
echo '<td>';
// echo "<img src=\"\\images\\$file\"
width='142'height='142'>";
// echo "<img src=\"\\images\\$file\"
width='142'height='142'>";
echo "<img src=\"\\images\\$thefiles[$c]\"
width='142'height='142'>";
echo "<img src=\"\\images\\$thefiles[$d]\"
width='142'height='142'>";
//echo "<img
src=\"\\images\\$thefiles[$c(+2)]\" width='142'height='142'>";
// $c=$c+1 ; echo $c;
echo $c;

echo '</td>';
echo '</tr>';


}
echo '</table>';
$mydir->close();


?>
<p> test</p>




</body>
</html>



Reply With Quote
  #2 (permalink)  
Old 02-02-2004
Doug Bonomo
 
Posts: n/a
Default Re: increment an array element to display jpg's ...

I played around for a few minutes and made an example for you, I think this
captures what you want to do....

http://ghost.3drealm.net/imagetable.php

<?php
// just setting a path variable to simplify writing
$path = "puppies/images/puppies/";
// how many columns do you want? can be set to whatever
$cols = 4;

$mydir = dir($path);

$lines = "<table border=3>\n";

while ($file = $mydir->read())
{
$fullpath = $path.$file;
if (GetImageSize($fullpath))
{
// Increment $c up 1 each cycle thru
$c++;
// If this is the first entry on the row start the table
row.
if ($c == 1) { $lines .= "<tr>\n"; }
$lines .= "<td><img src='$fullpath' width=150></td>\n";
// If this is the last column close the row and set $c to 0
if ($c == $cols) { $lines .= "</tr>\n"; $c = 0; }
}
}
// now finish out the table columns just to be complete
if ($c < $cols)
{
$colstogo = $cols - $c;
$lines .= "<td colspan=$colstogo>&nbsp;</td>\n";
}
// and add in the closing tag to make netscape happy.
$lines .= "</table>";
echo $lines;
?>

This is the un*x version, freebsd actually, so the file pathing is different
but the code should work just the same.

Doug B.
===============================================
"J Bard" <support@41north.net> wrote in message
news:21dTb.6520$GO6.4547@newsread3.news.atl.earthl ink.net...
> I'm reading a directory of pictures , and trying to display them nicely
> formated in a table 4 accross...
> a few issues ..
>
> My play with array's don't work ...I'm able to feed pictures into array's
> ,with
> $thefiles[$c] = $file;
>
> but when I try to call the pictures
> echo "<img src=\"\\images\\$thefiles[$c]\" width='142'height='142'>";
> works but
>
> thefiles[$c+1]
>
> bombs ! If I can't manually increment the array I don't see how to do

this
> .
>
>
> the whole thing at the moment is:
>
> <html>
> <head>
> <title>PHP Test</title>
> </head>
> <body>
>
> <?php
>
> $mydir = dir('images');
> ?>
> <?php $thefiles=array(); ?>
> <?php echo '<table border="3">'; $c=0 ?>
>
> <?php
>
> while(($file = $mydir->read()) !== false) {
>
> $c=$c+1 ; // echo $c;
> $d=($c+=2);
> $thefiles[$c] = $file;
>
>
> echo '<tr>';
> echo '<td>';
> // echo "<img src=\"\\images\\$file\"
> width='142'height='142'>";
> // echo "<img src=\"\\images\\$file\"
> width='142'height='142'>";
> echo "<img src=\"\\images\\$thefiles[$c]\"
> width='142'height='142'>";
> echo "<img src=\"\\images\\$thefiles[$d]\"
> width='142'height='142'>";
> //echo "<img
> src=\"\\images\\$thefiles[$c(+2)]\" width='142'height='142'>";
> // $c=$c+1 ; echo $c;
> echo $c;
>
> echo '</td>';
> echo '</tr>';
>
>
> }
> echo '</table>';
> $mydir->close();
>
>
> ?>
> <p> test</p>
>
>
>
>
> </body>
> </html>
>
>
>



Reply With Quote
  #3 (permalink)  
Old 02-02-2004
Duyet The Vo
 
Posts: n/a
Default Re: increment an array element to display jpg's ...

I would first read the dir, put all the images into the array:

$mydir = dir('images');
$thefiles = array();
while(($file = $mydir->read()) !== false) {
if ( is_file ( $file )) {
// might want to check if it's really images
// and not text, or something else
$thefiles[] = $file;
}
}
$mydir->close();

Then format and print the table.

foreach ( $thefiles as $value ) {
// table stuff
echo "<img src='$value' width='142'height='142'>\n";
// table stuff
}

HTH.

"J Bard" <support@41north.net> wrote in message
news:21dTb.6520$GO6.4547@newsread3.news.atl.earthl ink.net...
> I'm reading a directory of pictures , and trying to display them nicely
> formated in a table 4 accross...
> a few issues ..
>
> My play with array's don't work ...I'm able to feed pictures into array's
> ,with
> $thefiles[$c] = $file;
>
> but when I try to call the pictures
> echo "<img src=\"\\images\\$thefiles[$c]\" width='142'height='142'>";
> works but
>
> thefiles[$c+1]
>
> bombs ! If I can't manually increment the array I don't see how to do

this
> .
>
>
> the whole thing at the moment is:
>
> <html>
> <head>
> <title>PHP Test</title>
> </head>
> <body>
>
> <?php
>
> $mydir = dir('images');
> ?>
> <?php $thefiles=array(); ?>
> <?php echo '<table border="3">'; $c=0 ?>
>
> <?php
>
> while(($file = $mydir->read()) !== false) {
>
> $c=$c+1 ; // echo $c;
> $d=($c+=2);
> $thefiles[$c] = $file;
>
>
> echo '<tr>';
> echo '<td>';
> // echo "<img src=\"\\images\\$file\"
> width='142'height='142'>";
> // echo "<img src=\"\\images\\$file\"
> width='142'height='142'>";
> echo "<img src=\"\\images\\$thefiles[$c]\"
> width='142'height='142'>";
> echo "<img src=\"\\images\\$thefiles[$d]\"
> width='142'height='142'>";
> //echo "<img
> src=\"\\images\\$thefiles[$c(+2)]\" width='142'height='142'>";
> // $c=$c+1 ; echo $c;
> echo $c;
>
> echo '</td>';
> echo '</tr>';
>
>
> }
> echo '</table>';
> $mydir->close();
>
>
> ?>
> <p> test</p>
>
>
>
>
> </body>
> </html>
>
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:50 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0