On Tue, 15 Oct 2002, Dermot Paikkos wrote:
> 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>
If data is an array of arrays, then it seems like the syntax you
want would be something like:
[% FOREACH item = data %]
<tr>
<td>item1=[% item.0 %]</td>
<td>item2=[% item.1 %]</td>
<td>item3=[% item.2 %]</td>
</tr>
[% END %]
Of course, you could always let Template::Plugin::DBI do the heavy
lifting:
[% USE DBI(db, user, pass) %]
[% users = DBI.query('SELECT id,name,surname FROM users') %]
[% FOREACH user = users %]
<tr>
<td>item1=[% item.id %]</td>
<td>item2=[% item.name %]</td>
<td>item3=[% item.surname %]</td>
</tr>
[% END %]
I hope that helps.
Take care,
Dave
/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash Power to the People!
Frolicking in Fields of Garlic Right On-Line!
[EMAIL PROTECTED] Dig it all.
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates