chimni has asked for the wisdom of the Perl Monks concerning the following question:
site router interface dlh 138.188.193.233 FastEthernet0/0 dlh 138.188.193.233 Serial0/0
use strict; use warnings; use DBI; use HTML::Template; use Log::Log4perl; Log::Log4perl->init("/home/ndb/config/dlh_ndb_log.conf"); my $log = Log::Log4perl->get_logger(); my $template = new HTML::Template(filename=>"home1.tmpl"); my $dbh = DBI->connect('dbi:mysql:ndb','esm','esm') || die "Cannot con +nect"; #print "\n Connected....."; my @loop_data; my @sites; my @routers; my $query = "select distinct site_name from sites order by site_name"; my $sth = $dbh->prepare($query); $sth->execute; my $query_router = "select distinct router from sites where site_name += ?"; my $sth_router = $dbh->prepare($query_router); my $query_interface = "select interface from sites where site_name = ? + and router = ?"; my $sth_interface = $dbh->prepare($query_interface); while(@sites = $sth->fetchrow_array) { my @r_loop_data; $sth_router->bind_param(1,$sites[0]); $sth_router->execute; while(@routers = $sth_router->fetchrow_array) { my @interfaces; $sth_interface->bind_param(1,$sites[0]); $sth_interface->bind_param(2,$routers[0]); $sth_interface->execute; while(my @arr = $sth_interface->fetchrow_array) { my %interface_row = ( interface => $arr[0] ); push(@interfaces, \%interface_row); } my %row; %row = ( router => $routers[0] , interfaces_loop => \@interfaces ); push(@r_loop_data,\%row); } my %site_row = ( site => $sites[0], routers_loop => \@r_loop_data ); push(@loop_data, \%site_row); } $template->param(caption => "ST Sites"); $template->param(sites_loop => \@loop_data); print "Content-Type: text/html\n\n"; print $template->output; $dbh->disconnect or $log->logwarn("Cannot disconnect from the database +: $DBI::errstr"); exit 0;
<html> <body LINK="blue" ALINK="green" VLINK="#4169e1"> <table border="0" CELLPADDING="20" CELLSPACING="20" WIDTH="1000"> <tr> <td align = "center"><TMPL_INCLUDE NAME = "/var/www/cgi-bin/nd +b_header.tmpl"></td> </tr> <tr> <td align = "center"> <table border="1" CELLPADDING="0" CELLSPACING="0" WIDTH="1 +00%"> <caption > <b><TMPL_VAR NAME = "caption"></b> </h2> <TMPL_LOOP NAME="sites_loop"> <tr bgcolor = "cornflowerblue" text = "white"> <th colspan = "2" align = "left"><font color="white"> +<TMPL_VAR NAME = "site"></font></th> </tr> <TMPL_LOOP NAME="routers_loop"> <tr bgcolor = "powderblue"> <td align = "left"><font color = "navy"><b><TMPL_V +AR NAME="router"></b></font></td> <td align = "left"><TMPL_LOOP NAME = "interfaces_loop" +><a href = "display_graph.cgi?router=pdel246&interface=FastEthernet0/ +0"><TMPL_VAR NAME="interface"></a> | </TMPL_LOOP></td> </tr> </TMPL_LOOP> </TMPL_LOOP> </table> </td> </tr> <tr> <td align = "center"><TMPL_INCLUDE NAME = "/var/www/cgi-bin/nd +b_footer.tmpl"></td> </tr> </table> </body> </html>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: HTML::Template : generation of links
by jeffa (Bishop) on Apr 12, 2004 at 16:15 UTC |