RE: [htmltmpl] Adding to a row in a loop
Brought to you by:
samtregar
|
From: Todd S. <zo...@pa...> - 2002-08-06 01:05:11
|
Hi Kenny,
Thanks for the suggestion but I think I need to try to explain better what
I'm trying to accomplish. I have a template as follows:
----------------Temp Snip------------------
<TMPL_LOOP NAME="results">
<tr>
<td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='cid'></FONT></th>
<td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='companyName'></FONT></th>
<td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='address'></FONT></th>
<td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='city'></FONT></th>
<td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='phone'></FONT></th>
<Td><form method=post action="/cgi-bin/sv.cgi">
<input type=hidden name=rm value="selectClient">
<input type=hidden name=cid value="<TMPL_VAR NAME='cid'>">
<input type=hidden name=uname value="<TMPL_VAR NAME='uname'>">
<input type=submit value="Select"></td>
</tr>
</TMPL_LOOP>
----------------end------------------------
All the above variables are filled from my SQL SELECT statement, except for
"uname" which is a tag I want to add to each row. How do I add that value
to what I'm getting back with my "$data = $sth->fetchrow_hashref()"
statement so that it gets filled in when H::T runs the above loop?
Thanks!
-----Original Message-----
From: htm...@li...
[mailto:htm...@li...]On Behalf Of
Kenny Smith
Sent: Monday, August 05, 2002 5:24 PM
To: zo...@pa...; htm...@li...
Subject: RE: [htmltmpl] Adding to a row in a loop
Hi Todd,
I'm not exactly sure what you are trying to do that you aren't actually
accomplishing with the code you provided, but in any case, I would suggest
something more like this:
-------- snip ----------
my $template = HTML::Template->new( filename => 'showclient.html' ) ;
my $rc = $sth->execute() ;
my ( $data , $rows );
while( $data = $sth->fetchrow_hashref() ) {
push( @{$rows} , $data ) ;
}
$template->param( { results => $rows } ) ;
print $template->output() ;
-------- end ------------
It's a good idea to never set $_ yourself... you should always use your
own variable.
Kenny
-----Original Message-----
From: htm...@li...
[mailto:htm...@li...]On Behalf Of
Todd Schacherl
Sent: Monday, August 05, 2002 4:53 PM
To: htm...@li...
Subject: [htmltmpl] Adding to a row in a loop
Hi Folks,
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?
my $rc = $sth->execute();
my $tmpl_obj;
# prepare a data structure for HTML::Template
my $rows;
push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
# instantiate the template and substitute the values
$tmpl_obj = $self->load_tmpl('showclient.html');
$tmpl_obj->param(results => $rows);
Thanks in advance,
Todd Schacherl
ht...@zo...
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Html-template-users mailing list
Htm...@li...
https://lists.sourceforge.net/lists/listinfo/html-template-users
|