want to display arrays of data in table using template file in perl -
i have different arrays of data stored sql :
push( @bugid,$bug_id); push(@assign,$assignd_to); push(@stat,$stats); push(@res,$resol); push(@rat,$rate); push(@sev,$prior); push(@op,$o_p); push(@shrt,$shor_desc); $vars->{'bugid'}= \@bugid; $vars->{'ticket'}= $ticket_no; $vars->{'assigne'}= \@assign; $vars->{'stats'}= \@stat; $vars->{'resoltion'}= \@res; $vars->{'rate'}= \@rat; $vars->{'priorty'}= \@sev; $vars->{'opsys'}= \@op; $vars->{'shrtdesc'}= \@shrt;
and have passed template file displaying purpose below :
$template->process('reports/gayathri_old-ticketlist.html.tmpl', $vars) || throwtemplateerror($template->error());
and want display details in table . ie, corresponding each bugid, want display other fields.
i have added code in template file.i got table format.but values entering each column in wrong manner.
<table border='1' bgcolor='#eefff3'> <tr><td><b>bug id</b></td> <td><b>ticket no</b></td> <td><b>assigned to</b></td> <td><b>bug status</b></td> <td><b>resolution</b></td> <td><b>rating</b></td> <td><b>priority</b></td> <td><b>op-sys</b></td> <td><b>short description</b></td></tr> [% foreach assigne = assigne %] [% foreach stats = stats %] [% foreach resoltion = resoltion %] [% foreach rate = rate %] [% foreach priorty = priorty %] [% foreach opsys = opsys %] [% foreach shrtdesc = shrtdesc %] [% foreach bugid = bugid %] <tr> <td> <a href="show_bug.cgi?id=[% bugid %]"> [% bugid %] </a><br> </td> <td> [% ticket %] </td> <td> [% assigne %] </td> <td> [% stats %] </td> <td> [% resoltion %] </td> <td> [% rate %] </td> <td> [% priorty %] </td> <td> [% opsys %] </td> <td> [% shrtdesc %] </td> </tr> [% end %] [% end %] [% end %] [% end %] [% end %] [% end %] [% end %] [% end %] </table>
could 1 please correct this?
all nested foreach
statements going create loops within loops. i'd that's why you're not getting output want. i'm not sure impact of redefining variables (foreach bugid = bugid
etc) be.
the data design horrible, work it, doing like:
[%- set = 0; while < bugid.size; -%] <tr> <td> <a href="show_bug.cgi?id=[% bugid.$i %]"> [% bugid.$i %] </a><br> [% assigne.$i %]<br/> ...etc </td> </tr> [%- set = + 1; end -%]
... iterating through elements of one of arrays, , using ordinal position all of them. bugid.$i
resolves bugid.0
first element in array.
but wouldn't that.
i generate original data array of hashrefs, , iterate through them.
== perl ==
my @items; # in loop $item = { bugid => $bugid, assign_to => $assign_to, status => $stat, ..etc }; push @items, $item; # end of loop $vars->{items} = \@items;
== template ==
[%- foreach item in items -%] <tr> <td> <a href="show_bug.cgi?id=[% item.bugid %]"> [% item.bugid %] </a><br> [% item.assign_to %]<br/> ...etc </td> </tr> [%- end -%]
hope that's helpful. , pity's sake, decide on naming convention variables , stick it. fellow programmer once put me: "a standard sucks better changing one." :-)
Comments
Post a Comment