Always group reply so that others can help and be helped and to avoid
getting (accidentally) ignored.

>
-----------------------------------------------------------------------------------------------
> "But I need the output as an array like @db_results
> which would be sent 
> to a HTML template."
> The @db_results would look like
> 
> db_results[0] = A      90  89  0   0
> db_results[1] = B  70  71  71  0
> db_results[2] = C   0  73  97  0
> 

In this case you need to make an attempt. I have shown you an easy way
to build a structure that will make manipulating the data simple. You
need to put the effort into taking it the next step, if you fail, show
us what you tried and what the errors are, we are not here to write it
for you.

perldoc -f push
perldoc -f sprintf

Should give you a hint.

http://danconia.org

-------------------------------------------------------------------------------------------------
> 
> Regards
> Rohit Satabhai
> 
> 
>  --- Wiggins d Anconia <[EMAIL PROTECTED]> wrote: 
> > >
> >
> ==========================================================================
> > > Using DBI Perl Programming I get a database o/p as
> > > below
> > > Student             SubjectCode        Marks
> > > ------------------------------------------------
> > > A                       1                90
> > > A                       2                89
> > > B                       1                70
> > > B                       2                71
> > > B                       3                71
> > > C                       2                73
> > > C                       3                97
> > > -------------------------------------------------
> > > Subject code may vary to any value.
> > > I need a report o/p in the following format and
> > > displayed in HTML
> > > Student             1   2  3  4   
> > > ------------------------------------------------
> > > A                  90  89 
> > > B                  70  71  71
> > > C                      73  97
> > > -------------------------------------------------
> > >
> >
> ================================================================
> > 
> > I am not sure why you chose an array as your top
> > level structure.
> > Assuming each student is unique, and each subject is
> > unique, you can use
> > a hash of students, with the values of that being a
> > hash of subjects,
> > with the value being the mark. This eliminates the
> > need for all the
> > index munging.  For me it would look something like:
> > 
> > use strict;
> > use warnings;
> > 
> > my $sth = [
> > 
> > { 'student' => 'A', 'subject' => '1', 'mark' =>'90'
> > },
> > { 'student' => 'A', 'subject' => '2', 'mark' =>'89'
> > },
> > { 'student' => 'B', 'subject' => '1', 'mark' =>'70'
> > },
> > { 'student' => 'B', 'subject' => '2', 'mark' =>'71'
> > },
> > { 'student' => 'B', 'subject' => '3', 'mark' =>'71'
> > },
> > { 'student' => 'C', 'subject' => '2', 'mark' =>'73'
> > },
> > { 'student' => 'C', 'subject' => '3', 'mark' =>'97'
> > },
> > 
> > ];
> > 
> > my $students;
> > foreach my $row (@$sth) {
> > #while (my $row = $sth->fetchrow_hashref) {
> >    
> > $students->{$row->{'student'}}->{$row->{'subject'}}
> > = $row->{'mark'};
> > }
> > 
> > foreach my $student (sort keys %$students) {
> >     print $student, "\t";
> >     foreach my $subject (sort keys
> > %{$students->{$student}}) {
> >         print "\t",
> > $students->{$student}->{$subject};
> >     }
> >     print "\n";
> > }
> > 
> > I have simulated your select above with the data you
> > provided, switch
> > the C<foreach> to the commented C<while> to have it
> > use the actual
> > statement handle.
> > 
> > You can use C<printf> or formats to get the columns
> > to line up right.
> > 
> > <snip code>
> > 
> > >
> >
> =============================================================
> > > Is there any other way in which this could be
> > coded
> > > efficiently.
> > > Regards
> > > Rohit
> > 
> > There is always another way. Better is always
> > debatable....
> > 
> > Some Lite reading:
> > 
> > perldoc perllol
> > perldoc perldsc
> > perldoc perlreftut
> > perldoc perlref
> > 
> > http://danconia.org
> > 
> > -- 
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > <http://learn.perl.org/>
> > <http://learn.perl.org/first-response>
> > 
> > 
> >  
> 
> ________________________________________________________________________
> Yahoo! India Matrimony: Find your partner online.
http://yahoo.shaadi.com/india-matrimony/
> 
> 
> X-UIDL: Q`>!!QdS"!aj8"!D3'#!
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to