in reply to Re: Template::Toolkit - How do i access alias-based results?
in thread Template::Toolkit - How do i access alias-based results?

I understand what you're saying but this doesn't help me on my issue right now. I already did it the other way around, receive first in perl and pass as param to template, but same result anyway...

print "Content-type: text/html\n\n"; my $oTT = Template->new({ INCLUDE_PATH => '../templates', EVAL_PERL => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; # DB - Connect my $hDB = DBI->connect( "dbi:Oracle:xe", "lp", "lpdba", { AutoCommit = +> 0 } ); my $hStatement = $hDB->prepare(" SELECT v.vertragsnummer, a.artikelnr, v.status, v.datum, v.nachric +ht FROM vertraege v, artikel a, benutzer b, lieferanten l, mandanten +m [...]"); $hStatement->execute( ); while ( ( $iVertragsnummer, $sArtikelNr, $sVertragsStatus, $sVertragsD +atum, $iMsgID ) = $hStatement->fetchrow_array() ){ push (@aRows, ( $iVertragsnummer, $sArtikelNr, $sVertragsStatus, $s +VertragsDatum, $iMsgID )); } $hStatement->finish; $hDB->disconnect; my $sData = { 'result' => \@aRows }; $oTT->process("../templates/mytemp.html", $sData) || die $oTT->error() +, "\n";

Replies are listed 'Best First'.
Re^3: Template::Toolkit - How do i access alias-based results?
by tangent (Parson) on Jul 13, 2015 at 14:28 UTC
    Using that code your @aRows will end up like this:
    row1-iVertragsnummer row1-sArtikelNr row1-sVertragsStatus row1-sVertragsDatum row1-iMsgID row2-iVertragsnummer row2-sArtikelNr row2-sVertragsStatus row2-sVertragsDatum row2-iMsgID ...etc
    I suspect you need something like this:
    { iVertragsnummer => 'row1-iVertragsnummer', sArtikelNr => 'row1-sArtikelNr', }, { iVertragsnummer => 'row2-iVertragsnummer', sArtikelNr => 'row2-sArtikelNr', },
    So try changing to:
    while ( my $row = $hStatement->fetchrow_hashref() ) { push ( @aRows, $row ); }
      Yeah this fixed it. I was trying around with fetchrow_arrayref but then I was in an endless loop. I should have better taken hasref ;)

      Anyway, thank you sir.

      Bingo.   I think that the data-structure is wrong.   Data::Dumper will quickly show you what the data actually looks like, and (as noted elsewhere) so will Template itself.

      What you need to come up with is an array of hashrefs, one per record, preferably the correct “slice” of a larger result set.   The template then loops through this array.