Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Images, in links, in tables..... utter choas

by wiz (Scribe)
on Jul 27, 2001 at 23:40 UTC ( [id://100427]=perlquestion: print w/replies, xml ) Need Help??

wiz has asked for the wisdom of the Perl Monks concerning the following question:

Well here is my code... I *tried* to add the feature of using the thumbnail image as a link to the screen res image, and all hell broke loose. can someone help me here? Here's the code, and the DB is intact, i know that isn't a problem: (and it runs from the command line fine)
#!/usr/bin/perl -w use strict; use CGI qw(:standard); print header(), start_html("Street Print CD Catalog"), h1("StreetPrint CD Catalog"); if (param()) { my @supersaver = qw(Name Color Pattern CD_number Thumbnail_Image); chomp(my $color = param("color")); chomp(my $pattern = param("pattern")); chomp(my $cd_number = param("cdnumber")); print p(h4('You searched for:'),br(), h5("Color : $color"), h5("Patter +n : $pattern"), h5("Cd Number : $cd_number")); print table({-border=>1},Tr({-align=>'CENTER',-valign=>'MIDDLE'}, [td( +{-width=>'150'}, [b($supersaver[0]), b($supersaver[1]), b($supersaver +[2]), b($supersaver[3]), b($supersaver[4])])])); open (DBFILE, "<scform.db") or die "$!"; while (my $line = <DBFILE>) { chomp $line; my @record = split /\|/, $line, 6; ## $record[0] is name, 1 => color, 2 => pattern, 3 => cd, 4 => thumbna +il picture, 5=> screen res picture. ## C = color, P = Pattern, # = Cd Number, a = any if( $color eq "Any" || $record[1] =~ /^$color$/i and $pattern eq "Any" || $record[2] =~ /^$pattern$/i and $cd_number eq "Any" || $record[3] =~ /^$cd_number$/i ) { print table({-border=>1},Tr({-align=>'CENTER',-valign=>'MIDDLE'}, +[td({-width=>'150'}, [$record[0], $record[1], $record[2], $record[3], + [(start_a({-href=>"/images/screenres/$record[5]"}),img({-src=>"/imag +es/thumbnails/$record[4]"}), end_a())]])])); next; } } close (DBFILE); } else { ## stuff that doesn't matter to this problem }


This is the site.
Thanks for all your help.
----------------------------
Wiz, The VooDoo Doll
Head Master of 12:30 Productions
----------------------------

Replies are listed 'Best First'.
(Daddio) Re: Images, in links, in tables..... utter choas
by Daddio (Chaplain) on Jul 28, 2001 at 01:06 UTC

    wiz, unless you have a start_a and end_a function defined somewhere (I don't see them in my CGI.pm), I think that is where your problem lies.

    Try changing your

    start_a({-href=>"/images/screenres/$record[5]"}),img({-src=>"/images/thumbnails/$record[4]"}), end_a()

    to something like this (broken up for clarity):

    a({-href=>"/images/screenres/$record[5]"}, img({-src=>"/images/thumbnails/$record[4]"}) )

    I think that may help.

    D a d d i o

Re: Images, in links, in tables..... utter choas
by Cirollo (Friar) on Jul 27, 2001 at 23:56 UTC
    Can you be a little more specific on what is going wrong? What are you seeing when you run it from the web? Do you have any errors from your server error log?

    Update: I'm not sure exactly what is wrong, but you might consider dumping the CGI.pm html-printing stuff for your tables; it gets quite messy when used on tables.

    Also, instead of saying $record[0], $record[1], $record[2], $record[3], you can use array slices and write it as @record[0..3].

Re: Images, in links, in tables..... utter choas
by MrCromeDome (Deacon) on Jul 27, 2001 at 23:54 UTC
    Can you please define "all hell breaks loose"? Does your server give a dreaded 500 error? Something else? It's very hard for some of us to give sound advice without some additional info. Especially because we can't run your script without your DB or images.

    For starters though, make your first three lines:

    $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser');
    MrCromeDome
Re: Images, in links, in tables..... utter choas
by thatguy (Parson) on Jul 28, 2001 at 01:06 UTC
    much like Cirollo suggested, I substituted

    print table({-border=>1},Tr({-align=>'CENTER',-valign=>'MIDDLE'}, [td({-width=>'150'}, [$record[0], $record[1], $record[2], $record[3], [(start_a({-href=>"/images/screenres/$record[5]"}),img({-src=>"/images/thumbnails/$record[4]"}), end_a())]])]));

    for

    print "<table border=1><tr align=center valign=middle><td width=150>$record[0]</td><td width=150>$record[1]</td><td width=150>$record[2]</td><td width=150>$record[3]</td><td width=150><a href=/images/screenres/$record[5]><img src=/images/thumbnails/$record[4]></td></tr></table>\n";

    while not perfect, it seems to work. -phill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://100427]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found