At earth time Sun, 11 Jan 2004 06:47:28 -0800, the following transmission
was received from the entity known as Oli Waters:
> Hi everyone
>
> I have set up a simple online shopping webpage in which a user selects
> a product type and then clicks 'view products'. The data is then
> retrieved from a mysql database and displayed on the page. All this
> works fine apart from one part. I want to display a picture of the
> product. In my database the column PRODDESC contains a link to a
> picture on my hard disk. How do i code it so that it actually displays
> the picture rather than displaying the link itself. Here is the
> offending code....
>
> ## Execute query
> my @rs = DBQuery($dbh, "SELECT PRODUCTID, PRODDESC, DATEADDED, PRICE
> FROM PRODUCTS WHERE ORDERNO IS NULL AND PRODTYPE=\"$_[0]\"")
> or die("DBQuery: $DBI::errstr");
>
> ## For each dataset row print in table row
> foreach (@rs) {
>
> ## Set table row's background colour
> $trbgcolor=($yellow)?"#F7F7DE":"white";
> print "<tr height=40 style='background-color:$trbgcolor;'>";
> $i=0;
>
> ## Print add to cart button and product details
> print "<td align=left><input class=bluebutton
> onclick='AddToCart(this);' type=button value='Add to Cart'
> name='@$_[0]'></td>";
> print "<td><p>@$_[1]</p></td>"; <--- IM SURE ITS THIS BIT!!
> print "<td><p>@$_[2]</p></td>";
>
> # Round price to 2 decimal places
> print "<td><p>£" . sprintf("%.2f", @$_[3]) . "</p></td>";
>
> I've labelled the thing i think is wrong...do i need an src= or
> something??
>
> Thanks in advance
>
> Oli
Something looks odd to me in the way you've referenced the query results.
I'm guessing that DBQuery puts an array of arrayrefs into @rs, similar to
if you do $ar=$query->fetchall_arrayref; in DBI, but some things about the
code above don't sit right with that. One is that foreach without a
variable isn't defined in the perl syntax manual page, but maybe it is
part of the perl standard. Assuming that's OK, and the variable $_ gets
used instead, what you probably want is:
print "<td>${$_}[1]</td>";
by using @$_[1], I think you're referencing a whole array whose reference
is stored in the second element of @_, rather than the second element from
the array referenced by $_.
Also, the pictures need to be stored somewhere in the public directory
tree of your web or ftp server for you to be able to reference them like
this.
E.g. if you had a top-level directory called ProductImages in your web
space, then you'd want to print links like:
<img src="/ProductImages/Prod0123345.jpg">
HTH. andy.
--
http://www.niftybits.ukfsn.org/
remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.