Ok I got lots of answers and I think I need to say thanx to:
Chris Winters, Brain Parker, Rafis Ismail, Dave Cash and Axel
Gerstmair.
To be honest from what a lot of you said I think there might be
problems in my code or my understanding of it. Dave has given me
an answer that works for now though.
[% FOREACH item = data %]
<tr>
<td>item1=[% item.0 %]</td><td>item2=[% item.1
%]</td><td>item3=[% item.2 %]</td>
</tr>
[% END %]
</table>
Which yields:
item1=1 item2=Anna item3=Bond
item1=2 item2=Brandon item3=Broll
item1=3 item2=Rosa item3=Caballero
To get this my script reads:
(my @data) = &getusers();
sub getusers {
.....
while (my ($id,$name,$surname) = $sth->fetchall_arrayref) {
return $id,$name,$surname;
}
my $vars = {
data => @data,
};
$tt->process($file,$vars)
|| die $tt->error;
I am still confused about what type of data structure I am getting
back from &getusers. Most seem to agree I need a hashref
somewhere and without getting too off topic it might be that all my
records are dumped into $id.
Thanx again.
Dp.
========= original message =======
I have a perl script (mod_perl) that connects to a DB (using
APACHE:: DBI). I am trying to display 3 fields from all the records in
a table (about 55 records). The records come back as an array
reference (an array of arrays). I have been passing the arrayref to my
templates like so:
my $file = "test.atm";
my $vars = {
data => @data,
};
$tt->process($file,$vars)
|| die $tt->error;
At this point it gets scrappy - I can't find a way to display a 3
column table (or 3 anything) for each record. The best I can do is
this:
[% FOREACH item = data %]
[% FOREACH i = item %]
<tr>
<td>item1=[% i %]</td><td>item2=[% i.id
%]</td><td>items=[%i.name %]</td>
</tr>
[% END %]
[% END %]
</table>
This just gives me a single column long list with one field per row
(about 155 rows). I know i.id and i.name are meaningless in this
context, they are there to show what I'd really like.
I am pretty sure that I should be using another variable in the 2nd
FOREACH iterator but can work out from the docs how to do it. Can
someone spell it out for me?
Thanx.
Dp.
PS: Sorry if this mail has been received twice but I re-sent as I
hadn't received a copy from the list. ~~ Dermot Paikkos *
[EMAIL PROTECTED] Network Administrator @ Science Photo
Library
Phone: 0207 432 1100 * Fax: 0207 286 8668
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates
------- End of forwarded message -------
~~
Dermot Paikkos * [EMAIL PROTECTED]
Network Administrator @ Science Photo Library
Phone: 0207 432 1100 * Fax: 0207 286 8668
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates