in reply to normalizing results from a db query
...with a tmpl something like...my @tabular = $dbi->array_of_hashrefs_please(); # move into a hash (keyed by category) of array of hashrefs (rows) my %categories; foreach( @tabular ) { my $entry = $_->{ FIELD_I_WANT_TO_SORT_BY }; if ( $categories{$entry} == undef ) { $categories{$entry} = [$_] ; } else { push @{$categories{$entry}}, $_; } } # now create nested loop based on category... my @nested_loop; foreach(sort keys %categories) { push @nested_loop, { category => $_, entries => $categories{$_} +}; } # add our nested loop to the template $template->param( my_loop => \@nested_loop);
hope its of some use<tmpl_loop name="my_loop"> <tmpl_var name="category"> <tmpl_loop name="entries"> <!-- inner loop data here --> </tmpl_loop> </tmpl_loop>
|
|---|