Forum Moderators: coopster & phranque

Message Too Old, No Replies

photo album display - help changing code

         

victoryrun

6:19 am on Feb 15, 2003 (gmt 0)

10+ Year Member



Hi guys, me again. This one's probably easy for some of you. I've got a script that takes photos in a sub-dir of my server and displays them in a table. Problem is, it prints up to 3 med-sized pics into one row and sometimes (depending on pic size) it will stretch the screen and force a right/left scroll arrow to come up. I *hate* having that and was wondering if anybody could take a look at my code and tell me how I might be able to fix it to only allow two images displayed per row, or maybe setting the max row width to only say 500 pixels. Here's the code:

########################
sub table {
if ($caption_file ne "") {
open(CAPS,"$caption_file");
while (<CAPS>) {
chop;
($key,$value) = split(/:/);
$photos{$key} = $value;
}
close(CAPS);

foreach (sort keys %photos) {
push (@tnlist,$_);
push (@captions,$photos{$_});
}
}
else {
opendir (TN, "$tn_dir");
rewinddir (TN);
@tnlist = grep(!/^\.\.?$/, readdir (TN));
closedir (TN);
$temp = pop @tnlist;
@tntemp = reverse(@tnlist);
push (@tntemp,$temp);
@tnlist = reverse(@tntemp);
}

$tnnum = @tnlist;
$anum = int ($tnnum / 3);
$bnum = ((($tnnum / 3) - $anum) * 3);
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head>\n";
print "<body bgcolor=$bgcolor>\n";
print "$header\n";

if ($bnum eq "0") {
&main_table;
&end;
}
if ($bnum eq "1") {
&main_table;
print "<hr><table width=100% border=5 cellpadding=3>\n";
print "<tr align=center>\n";
print "<td width=33%></td>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[($anum * 3)]\"><br>$captions[($anum * 3)]<br></td>\n";
print "<td width=33%></td>\n";
print "</tr></table><hr>\n";
}
if ($bnum eq "2") {
&main_table;
print "<hr><table width=100% border=5 cellpadding=3>\n";
print "<tr align=center>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[($anum * 3)]\"><br>$captions[($anum * 3)]<br></td>\n";
print "<td width=34%></td>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[($anum * 3) + 1]\"><br>$captions[($anum * 3) + 1]<br></td>\n";
print "</tr></table><hr>\n";
}
print "$footer\n";
print "</body></html>\n";
}
sub main_table {
$dnum = ($anum * 3);
$cnum = "0";
while ($dnum > $cnum) {
print "<hr><table width=100% border=5 cellpadding=3>\n";
print "<tr align=center>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[$cnum]\"><br>$captions[$cnum]<br></td>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[$cnum + 1]\"><br>$captions[$cnum + 1]<br></td>\n";
print "<td width=33%><img src=\"$tn_dir_url/$tnlist[$cnum + 2]\"><br>$captions[$cnum + 2]<br></td>\n";
print "</tr></table>\n";
$cnum = $cnum + 3;
print "<hr>\n";
}
}
#################################

I see where there's 3 columns w/ 33% width, but don't think deleting just one of those lines would work. I'll probably screw up the script, so I figured I'd check with you all first! Thanks so much!

Ramsey

victoryrun

4:51 pm on Feb 15, 2003 (gmt 0)

10+ Year Member



Nevermind! I fixed it! I just deleted one instance of a TD when there were three and changed the width of the remainding two to 50%. Then I deleted all occurances of the number 3 and replaced with the number 2 and it worked! :-)

Thanks anyhow,
Ramsey