> I have some code like:
>
> while( $sth->fetch() ) {
> push(@id, $col_id);
> push(@firstname, $col_firstname);
> push(@lastname, $col_lastname);
> push(@address, $col_address);
> push(@phone, $col_phone);
> push(@email, $col_email);
> push(@code, $col_code);
> push(@function, $col_function);
> push(@confirmed, $col_confirmed);
> }
> $sth->finish;
> my $params = {
> 'id' => @id,
> 'firstname' => @firstname,
> 'lastname' => @lastname,
> 'address' => @address,
> 'phone' => @phone,
> 'email' => @email,
> 'code' => @code,
> 'function' => @function,
> 'confirmed' => @confirmed,
> };
>
> Where $col_foo is a MySQL column bound with
> $sth->bind_columns. For the
> sake of testing, I have left out any smartness. Eventually
> the idea is
> to take "confirmed" and convert it to a nicer true/false,
> hide ID, and
> do some formatting to "function". At the moment, I'm trying
> to test the
> code. My template follows:
>
> [% FOREACH id %]
> <b>id:</b> [% id %]<br>
> <b>First Name:</b> [% firstname %]<br>
> <b>Last Name:</b> [% lastname %]<br>
> <b>Address:</b> [% address %]<br>
> <b>Phone Number:</b> [% phone %]<br>
> <b>E-Mail Address:</b> [% email %]<br>
> <b>Code:</B> [% code %]<br>
> <b>Function:</B> [% function %]<br>
> <b>Confirmed:</B> [% confirmed %]<br>
> <hr><br>
> [% END %]
>
> Unfortunately, this results in the first result displayed and
> it fails
> to iterate over the array of data. How might I get this to
iterate
> through the arrays?
If you really want to iterate over several arrays simultaneously,
you have to use something like: [% lastname.${loop.index} %] or [%
lastname.unshift %].
But it is nad practice. I think you need something like this:
while( $sth->fetch() ) {
push(@items => {
id => $col_id,
firstname => $col_firstname,
lastname => $col_lastname,
address => $col_address,
### and so on...
});
}
$sth->finish;
my $params = {
'items' => [EMAIL PROTECTED],
};
And then, in template:
[% FOREACH item = items %]
<b>id:</b> [% item.id %]<br>
<b>First Name:</b> [% item.firstname %]<br>
<b>Last Name:</b> [% item.lastname %]<br>
<b>Address:</b> [% item.address %]<br>
[% # and so on ... %]
<hr><br>
[% END %]
--
Sergey Martynoff
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates