Looks like you have a lot of bad data in your database:
select distinct site_name from sites order by site_name;
select distinct router from sites where site_name = ?;
select interface from sites where site_name = ? and router = ?
but i don't really see much that we can do about it right now. In the meantime, why don't you try a simpler approach instead. Untested:
use DBI; use HTML::Template; my $dbh = DBI->connent( qw(dbi:mysql:ndb user pass), {RaiseError => 1}, ); my $sites = $dbh->selectall_arrayref(' select distinct site_name as name from sites order by site_name ',{Slice=>{}}); for my $site (@$sites) { $site->{routers} = $dbh->selectall_arrayref(' select distinct router as name from sites where site_name = ? ',{Slice => 1}, $site->{name}); #i removed the router = ? part from here #how do you expect to query a single router if there are multiples? $site->{interfaces} = $dbh->selectall_arrayref(' select interface as name from sites where site_name = ? ',{Slice => 1}, $site->{name}); } my $tmpl = HTML::Template->new(filehandle => \*DATA); $tmpl->param(sites => $sites); print $tmpl->output; __DATA__ <tmpl_loop sites> Name: <tmpl_var name> Routers: <tmpl_loop routers> <tmpl_var name> </tmpl_loop> Interfaces: <tmpl_loop interfaces> <tmpl_var name> </tmpl_loop> </tmpl_loop>
Select dictinct routers from a site, and then trying to only compare one of those to find the correct interface is surely not correct. You really should try to clean up your data first, garbage in --- garbage out. Give this code a shot and see what happens. At the very least, remove the parts of your code that don't matter. Don't worry about table formatting until you have correct data. Simplify. And read the HTML::Template Tutorial if you already haven't.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: HTML::Template : generation of links by jeffa
in thread HTML::Template : generation of links by chimni

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.