Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > displaying pictures in perl from mysql database

Reply
Thread Tools

displaying pictures in perl from mysql database

 
 
Oli Waters
Guest
Posts: n/a
 
      01-11-2004
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
 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      01-11-2004

"Oli Waters" <> wrote in message
news: m...
>
> How do i code it so that it actually displays
> the picture rather than displaying the link itself.


Most people would use an <img> tag to display graphics. Seems like you need
a good html book, or you could always try the w3 site www.w3.org or the
w3schools site: http://www.w3schools.com/.

Matt


 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      01-11-2004
On Sun, 11 Jan 2004 06:47:28 -0800, Oli Waters wrote:

> ## 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??


To display an image on a page, you need to use the 'img' tag. Use the
location of the image as the 'src' portion of the tag. If you continue to
have problems, post to a CGI authoring group - because this is an issue
with how you're creating your HTML, not really specific to Perl

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Nasrudin walked into a teahouse and declaimed, "The moon is more
useful than the sun." "Why?", he was asked. "Because at night
<we need the light more."
 
Reply With Quote
 
Andy Baxter
Guest
Posts: n/a
 
      01-12-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
using mysql client to read a file to create a table in a database in a mysql server julian Ruby 8 04-06-2006 10:29 AM
displaying pictures from a link in a mysql database Oli Waters Perl Misc 2 01-12-2004 08:14 AM
Displaying images from a MySQL Database Matt ASP .Net 0 08-01-2003 10:25 AM



Advertisments