#!/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=>"" }; # blank cell! } push @pictures,{row=>[$table_row]}; } $tmpl->param(thumbnails=>[@pictures]); print $q->start_html,$tmpl->@output,$q->end_html; } exit(0);