Just a general advice question more than anything, I need to create a website which links to a new web page, each has a unique picture and name such as something like this (http://www.molmovdb.org/cgi-bin/browse.cgi)
You don't give much to chew on with respect to why or what you are doing, but let me take a short in the dark on this:
In my view there isn't a single CPAN module that will address your needs. That said I'd recommend you look at both CGI (if you're not already familiar with it) and HTML::Template.
Consider the following mini-application:
#!/usr/bin/perl -w
##################################
# Filename: albuum.cgi
##################################
#
use strict;
use CGI;
use HTML::Template;
use DBI;
my $dbh = (mumble..muble...); # Put your connection logic here
my $q = CGI->new();
my $pic_id = $q->param('pic_id');
if ( $pic_id ) {
my $sth = $dbh->prepare(qq(
select picture_path from photo_album where picture_id = ?
) ) or die $dbh->errstr;
$sth->execute($pic_id) or die $sth->errstr;
my ($path)= $sth->fetchrow_array;
my $tmpl = HTML::Template->new(filename=>'picture_page.tmpl');
$tmpl->param(picture_path=>$path);
print $q->header(),$q->start_html(),$tmpl->output(),$q->end_html;
exit(0);
} else {
my $tmpl = HTML::Template->new(filename=>"show_album.tmpl");
my $sth= $dbh->prepare(qq(
select picture_id,title,path from photo_album order by title
)) or die $dbh->errstr();
$sth->executre();
my @pictures =();
my $count=0;
my $table_row = [];
while (my $row=fetchrow_hashref){
push @$table_row,$row;
$count++;
if($count > 2){
$count=0;
push @pictures,{row=>[$table_row]};
$table_row = [];
}
}
my @check_row = @$table_row;
if ((scalar @check_row) > 0 ) {
my $add_cols = 3 - (scalar @check_row);
for(my $i=1;$i<=$add_cols;$i++){
push @$table_row,{picture_id=>"",title=>"",path=>"" }; # bl
+ank cell!
}
push @pictures,{row=>[$table_row]};
}
$tmpl->param(thumbnails=>[@pictures]);
print $q->start_html,$tmpl->@output,$q->end_html;
}
exit(0);
What this does is on entry to the application it goes to a database and queries for a list of your pictures and pulls in a template to produce HTML that displays a table of thumbnails. Here is your template code for that:
/** show_album.tmpl **/
<table width="100%" border="1" align="center">
<TMPL_LOOP NAME=thumbnails >
<tr>
<TMPL_LOOP NAME=row>
<td>
<TMPL_IF NAME=picture_id>
<form action="/cgi-bin/album.cgi">
<hidden name="pic_id" value="<TMPL_VAR NAME=picture_id>">
<img src="<TMPL_VAR NAME=path>" width="75"><br>
<submit name="action" value="Pic Me!">
</TMPL_IF>
</td>
</TMPL_LOOP>
</tr>
</TMPL_LOOP>
That will render a table of three cells per row with a thumbnail of the pictures in the album. Pressing the "Pic Me!" button beneath each picture will bring you to a page with the full sized picture.
/** picture_page.tmpl **/
<p>
<a href="/cgi-bin/album.cgi"><lt;Back</a>
</p>
<div style="width: 80%; border outset 3px black; margin: auto;">
<img src="<TMPL_VAR NAME=path" style="margin: auto;">
</div>
CAVEAT: This code was all written before I finished my first coffee and was not tested.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
|