RE: [htmltmpl] Adding to a row in a loop
Brought to you by:
samtregar
|
From: Cory T. <ct...@on...> - 2002-08-06 00:23:54
|
1. Sorry this is HTML E-mail. I've been using this VS.NET IDE (ugh,)
which pastes very messy unless Outlook is in HTML mode. Sorry again, I
know, I hate me too.
2. I am thinking that you need help building an Array of Hashes for use
in a loop. We want to assemble each record from the database and then
append it to our loop construct. If I am incorrect, disregard this message.
[[[[[[[[ snip ]]]]]]]]
my $sth = $dbh -> prepare('select note_id, note_title, note_text,
course_id, module_id, section_id, page_id, user_id from tblNotes where
user_id = ? and course_id = ?');
$sth->execute($user_id, $course_id) or die "DB : Could not execute :
$DBI::errstr";
my @note_index;
while (my @rc = $sth->fetchrow_array() )
{
my %results;
%results->{'note_id'} = $rc[0];
%results->{'note_title'} = $rc[1];
push @note_index, \%results;
}
$sth->finish( );
return @note_index;
[[[[[[[[ snip ]]]]]]]]
I would later take @note_index and
$body->( NOTES => \@note_index ) ;
>
> I think this might be a basic PERL question but it does involve H::T. :o)
> But maybe somebody here can help me anyway...I'm using the loop
> ability with
> H::T to print out rows where each row is a form. I want to add a
> tag field
> for each row with the same data for that field in each row. How do I push
> that into the $rows that I pass to H::T?
You want to use an array of hashes. You make an array, and push the hash
ref onto it. You could also
unshift it.
>
> my $rc = $sth->execute();
> my $tmpl_obj;
>
> # prepare a data structure for HTML::Template
> my $rows;
> push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
That's obtuse ;)
> # instantiate the template and substitute the values
> $tmpl_obj = $self->load_tmpl('showclient.html');
> $tmpl_obj->param(results => $rows);
I think I am doing the same thing above, but my array is returned to another
module
that manages putting it into the H:T
>
> Thanks in advance,
Ok.
- Cory
|