Help needed: urgent
From: Rohit RS (rohit_tel_at_yahoo.com)
Date: 09/30/04
- Next message: Dave Gray: "Re: Trouble with m///g"
- Previous message: Chap Harrison: "Re: Trouble with m///g"
- Next in thread: Wiggins d Anconia: "Re: Help needed: urgent"
- Maybe reply: Wiggins d Anconia: "Re: Help needed: urgent"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Sep 2004 16:32:17 +0100 (BST) To: beginners@perl.org
==========================================================================
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
-------------------------------------------------
================================================================
The following code works out well for this
$sth->bind_columns (\$Student, \$subjectCode,
\$marks);
# chuck all the data into an array
my @ora_data;
my $index=0;
my $count=1;
while ($sth->fetch) #fetching the first row
{
#If its the first record assign the student id to
the first row
if ($count == 1) {
$ora_data[$index]{'STUDENT'} = $student;
$count++;
}
#Compare the student id of the array with the row
fetched from the
database
#if its not equal then create the next row in the
array and assign
the student to the row
if ( $ora_data[$index]{'STUDENT'} ne $student) {
$index++;
$ora_data[$index]{'STUDENT'} = $student;
}
#If the studentid in the array is equal to the row
fetched from the
database i.e sth->fetch
#Compare the subject code and assign the
appropriate value of marks
to the studentid.
if ($ora_data[$index]{'STUDENT'} eq $student) {
if ($subjectCode == 1) {
$ora_data[$index]{'MARK1'} = $marks;
}
elsif ($subjectCode == 2) {
$ora_data[$index]{'MARK2'} = $marks;
}
elsif ($subjectCode == 3) {
$ora_data[$index]{'MARK3'} = $marks;
}
elsif ($subjectCode == 512) {
$ora_data[$index]{'MARK4'} = $marks;
}
}
}
# close statement handler and pass the results back.
$sth->finish;
return @ora_data;
=============================================================
Is there any other way in which this could be coded
efficiently.
Regards
Rohit
-----------------------------------------------------------------
________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/
- Next message: Dave Gray: "Re: Trouble with m///g"
- Previous message: Chap Harrison: "Re: Trouble with m///g"
- Next in thread: Wiggins d Anconia: "Re: Help needed: urgent"
- Maybe reply: Wiggins d Anconia: "Re: Help needed: urgent"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|