> From: "Tom Ray [Lists]" <[EMAIL PROTECTED]>
>
> I'm having a bit of a formatting issue, and I was wondering if someone
> might have an idea on how to solve it. Basically what I have right now
> is a script that opens and reads the content of an image directory, each
> time the script is accessed it writes the contents out to a text file
> for me. I then open that text file and read it's contents, I want to be
> able to display thumbnail versions of the pictures, 3 per row and as
> many rows as needed. Unfortunetly, all I can do right now is 1 per row,
> this is where I need the help. Here's the code that displays images:
>
> $dat="$_GET[gallery].dat";
> $file=fopen($dat, 'r');
> $contents = fread ($file, filesize ($dat));
> fclose($file);
> $img=explode("|",$contents);
>
> print "<table width=50% cellpadding=0 cellspacing=3 border=0>";
>
> foreach($img as $image) {
> if($image) print "<tr><td><a href=$image><img src=\"$image\"
> width=150 height=100></a></td></tr>";
> }
> print "</table>";
>
> So how do I make this work so I can have three cells per table row and
> it actaully show the proper picture?
You need to set up a counter so you can start a new table row at the
appropriate time. Beginning from the line where you use explode(), and for
brevity not writing out the HTML for linking the image:
$img = explode("|", $contents);
$img_count = count($img);
$i = 0;
foreach ($img as $image) {
if ($i%3 == 0) {
echo("<tr><td>$image</td>");
if ($i+1 == $img_count) {
echo("</tr>\n");
}
} elseif ($i%3 == 1) {
echo("<td>$image</td>");
if ($i+1 == $img_count) {
echo("</tr>\n");
}
} elseif ($i%3 == 2) {
echo("<td>$image</td></tr>\n");
}
$i++;
}
Hope this helps.
--
Lowell Allen
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php