Hello Monks,

I have two images in a database that I would like to display on a web page.

When I run my script, the column that should have the image displays a "1". I do not understand why that is happening.

The first batch of code is a script that should be the link for the image. This has worked in a prior script for me.

#!/usr/bin/perl -Tw # serve_image.cgi - serve an image file as a Web page use CGI qw(:standard escape escapeHTML); use DBI; use strict; use CGI::Carp qw(fatalsToBrowser); use lib qw(/usr50/home/summitwe/public_html/library); use WebDB; #@ DISPATCH if (defined (param ("item_id"))) { display_image (param ("item_id"), param ("thumbnail")); } elsif (defined (param ("gallery"))) { display_gallery () } else { error ("Unknown request type"); } #@ DISPATCH exit (0); #@ DISPLAY_IMAGE sub display_image { my ($item_id, $show_thumbnail) = @_; my $col_name = (defined ($show_thumbnail) ? "thumbnail" : "picture"); my ($dbh, $mime_type, $data); $dbh = WebDB::connect (); ($mime_type, $data) = $dbh->selectrow_array ( "SELECT mime_type, $col_name FROM catalog_pet WHER +E item_id = ?", undef, $item_id); $dbh->disconnect (); # did we find a record? error ("Cannot find image named $item_id") unless defined ($mime_t +ype); print header (-type => $mime_type, -Content_Length => length ($dat +a)), $data; } #@ DISPLAY_IMAGE # Present gallery of names and images in the image table. Present the # thumbnail version of each image, but embed the image inside a hyperl +ink # that selects the full size image for display. #@ DISPLAY_GALLERY sub display_gallery { my ($dbh, $sth); print header (), start_html ("Image Gallery"); $dbh = WebDB::connect (); $sth = $dbh->prepare ("SELECT item_id FROM catalog_pet ORDER BY it +em_id"); $sth->execute (); # we're fetching a single value (name), so we can call fetchrow_ar +ray() # in a scalar context to get the value while (my $item_id = $sth->fetchrow_array ()) { # encode the name with escape() for the URL, with escapeHTML() + otherwise my $url = url () . sprintf ("?item_id=%s", escape ($item_id)); $item_id = escapeHTML ($item_id); print p ($item_id), a ({-href => $url}, # link for full size image # embed thumbnail as the link content to make it click +able img ({-src => "$url;thumbnail", -alt => $item_id}) ), "\n"; } $sth->finish (); $dbh->disconnect (); print end_html (); } #@ DISPLAY_GALLERY #@ ERROR sub error { my $msg = shift; print header (), start_html ("Error"), p (escapeHTML ($msg)), end_html (); exit (0); } #@ ERROR
The second batch of code is where I'm calling the link to display the image:
sub get_product_table { my $sth = shift; my @row; while (my $ref = $sth->fetchrow_hashref ()) { my $serve_url = sprintf ("serve_image.cgi?item_id=%s;thumbnail", +escape ($ref->{item_id})); # generate a form allowing a quantity of the item to be added # to the cart push (@row, start_form(-method=>'GET', -action=>url()), hidden( -name => "choice", -override => 1, -default => "add" ), hidden( -name => "item_id", -override => 1, -default => escapeHTML( $ref->{item_id} )), Tr ( td (print img ({-src => $serve_url, -alt => escapeHTML($ref->{item_ +id})})),

I want to display the thumbnail version of the image. As I mentioned, when I run my script, the column that should print the image, prints a "1" instead.

I can really use some help. I've been at this for a while now, and I'm not sure what to do.

Thanks.

update (broquaint): added <readmore> and formatting


In reply to Displaying Images using Perl by b310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.