> # the perlmongers example. doesn't work right either.
> #my $rows;
> #push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
This example should give you a good loop to use if you just say:
$template->param( PHRASE=>$search_phrase, SOL_LOOP => $rows );
instead of:
$template->param( PHRASE=>$search_phrase, SOL_LOOP => [ {$rows} ] );
The push into the array @{$rows} turns $rows into a reference to an array of
hashrefs, which happens to be the exact structure of a TMPL_LOOP. So you
don't have to do any sort of data type translation or use any brackets of
any sort when you define your loop, just plug your reference straight in
there. That should work, but if it doesn't send back some more detailed info
about what it's doing and what the error messages (if any) are.
Brian McCain
PageMasters Internet Group
----------------------------------------------------------------------------
------------
From: "Johnson, Nicole" <[EMAIL PROTECTED]>
Subject: [htmltmpl] tmpl_loops failing
> Hello -
>
> I'm having a problem getting tmpl_loop to spit out the actual list from a
> DBI select. I've got everything working so far, but it consistently only
> displays one item from the returned set. I'm pretty sure my problem is
how
> I'm handling the hash, but I've tried a variety of options from a variety
of
> websites and list archives to no avail (you'll notice all the # items that
> record what I have attempted). Any assistance would be appreciated, and a
> working example similar to what I'm trying to do would be good too.
>
> TIA -
> Nicole
>
> -------------------------------------------
> #-------------------------------------------------------
> # subroutine Keyword_Search
> #-------------------------------------------------------
>
> sub Keyword_Search {
>
> # log that we've begun
> print PERLLOG "$now: Preparing and executing statement
> Keyword_Search...\n";
> print PERLLOG "$now: SELECT description, solution FROM ahd.crsol
> WHERE description LIKE '%$search_phrase%'\n";
>
> # the values we want to fetch are longer than the 80 char default of
> DBI,
> # so we have to allow more to come through
> $dbh->{LongReadLen} = 1024 * 1024;
>
> my $sth = $dbh->prepare( "
> SELECT description, solution
> FROM ahd.crsol
> WHERE description LIKE '% $search_phrase %'
> " );
> $sth->execute();
>
> #my $i=0;
> #if (@row = $sth->fetchrow_array()) {
> # ($rd_desc, $rd_sol) = @row;
> # $i++;
> # print PERLLOG "$now: $rd_desc, $rd_sol\n";
> #} else {
> # $rd_desc = $rd_sol = "no data found";
> #}
> #print PERLLOG "$now: found $i\n";
> #$sth->finish();
>
>
> # the perlmongers example. doesn't work right either.
> #my $rows;
> #push@{$rows}, $_ while $_ = $sth->fetchrow_hashref();
>
> #print PERLLOG "$now: $rows\n";
>
> # make sure the query results are tied to perl variables so we can
> use them in the main program
> # 'rd' prefix means 'returned data'
> $sth->bind_col( 1, \$rd_desc );
> $sth->bind_col( 2, \$rd_sol );
>
> # put query output into an array
> # while we're there, determine if we have too many or not enough
> hits from the query
> my @stash;
> my $i=0;
> while ( $array_ref = $sth->fetchrow_arrayref ) {
> push @stash, [ @$array_ref ];
> $i++;
> }
>
> # doesn't work
> #my @loop_data = ();
> #while (@stash) {
> # my %row_data;
> # $row_data{DESC, SOL} = shift @stash;
> # push(@loop_data, \%row_data);
> #}
>
> #print PERLLOG "$now: found $i results\n";
>
> return;
> }
> exit;
>
> #----------------------------------------------------------------
> # subroutine doDisplay
> #
> # called when the data has been retrieved and verified, and
> # we are ready to push the output back to the user's browser.
> #----------------------------------------------------------------
>
> sub doDisplay {
>
> print PERLLOG "$now: starting doDisplay to show the output...\n";
>
> # open the HTML template
> my $template =
>
HTML::Template->new(filename=>'e:/inetpub/wwwroot/helpdesk/search_results.ht
> m');
>
> # generate output back to the browser
> #$template->param(
> # PHRASE=>$search_phrase,
> # DESC=>$rd_desc,
> # SOL=>$rd_sol,
> #);
>
> # works but displays funnily - at least it's looping
> #$template->param(SOL_LOOP => [
> # {
> PHRASE=>$search_phrase },
> # { DESC=>$rd_desc },
> # { SOL=>$rd_sol },
> # ]
> #);
>
> # works and displays right, but only one entry instead of ALL
> $template->param( PHRASE=>$search_phrase,
> SOL_LOOP => [
> { DESC=>$rd_desc,
> SOL=>$rd_sol },
> ]
> );
>
> # doesn't work
> #$template->param( PHRASE=>$search_phrase,
> # SOL_LOOP => [ {$rows} ] );
>
> print $template->output;
>
> return;
> }
> exit;
>
>
> M. Nicole Johnson
> CACP - Advanced Help Desk
> 713-420-1096 work
> 832-724-3215 cell
> 928-441-2504 efax
> mailto:[EMAIL PROTECTED]
>
>
>
> ******************************************************************
> This email and any files transmitted with it from the ElPaso
> Corporation are confidential and intended solely for the
> use of the individual or entity to whom they are addressed.
> If you have received this email in error please notify the
> sender.
> ******************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]