RE: [htmltmpl] How to Put reference array in to structure fro use in H::T?
Brought to you by:
samtregar
From: John <jo...@e-...> - 2004-09-28 10:23:04
|
From what you have described, you don't need a nested loop, so something like this example should do: Pick up your data, you can use execute and fetchall_arrayref methods if that suits you better. my $resultref = $dbh->selectall_arrayref('SELECT name, age, sex FROM People'); die("Database Error: " . $dbh->errstr) unless defined $resultref; Then map the results into an array (This is all one line). my @loop = map { { name => $_->[0], age => $_->[1], sex => $_->[2] } } @$resultref; Then send it to template. my $template = HTML::Template->new(filename => 'whatever.tmpl'); $template->param(LOOP => \@loop); print $template->output; In tmpl: <TMPL_LOOP NAME="LOOP"> <TMPL_VAR NAME="name"> - <TMPL_VAR NAME="age"> - <TMPL_VAR NAME="sex"><br> </TMPL_LOOP> Resulting HTML: Pete - 21 - Male<br> Sally - 26 - Female<br> Etc... Hope this helps. Cheers John -----Mensaje original----- De: htm...@li... [mailto:htm...@li...] En nombre de Dale W. Hanzelka Enviado el: lunes, 27 de septiembre de 2004 15:22 Para: htm...@li... Asunto: [htmltmpl] How to Put reference array in to structure fro use in H::T? I am using the Perl DBI to access a database. In particular, I' calling the fetchall_arrayref. How do I get the returned information into a usable structure so that I can loop through each row, then each column in the row? The returned info is as such: Reference --> Reference to Row0 --> ( col0, col1, col2, etc...) Reference to Row1 --> ( col0, col1, col2, etc...) etc... I can acceccs it using the below loop: foreach my $array (@array) { my($i, $j); for $i ( 0 .. $#{$array} ) { my $count = ($i + 1); print "ROW $count\t"; for $j ( 0 .. $#{$array->[$i]} ) { $array->[$i][$j] = "NULL" if ($array->[$i][$j] eq ""); print "$array->[$i][$j]\t"; } print "\n"; } } How do I get the information into correct structure to use as a nested loop in my template? Thanks in Advance! -Dale ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004 |