Help needed: urgent

From: Rohit RS (rohit_tel_at_yahoo.com)
Date: 09/30/04


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/



Relevant Pages

  • Re: KirbyBase
    ... creating objects from the database records was much easier. ... Hal, I don't know if you have had a chance to take a look at the beta yet, but I basically tried to implement a uniform way to specify one-to-one links, one-to-many links, and calculated fields in the ... I suppose it would in effect be embedding an array where all the ... My first couple of attempts at adding more complexity to KirbyBase did not honor this concept. ...
    (comp.lang.ruby)
  • Re: Policy Routing: Guaranteeing Bandwidth Question
    ... to our outsourced database ip address. ... No - because the saturation happens at the "choke point". ... matters at the point where some packets might get sent 1st, ... No student use of the link ...
    (comp.dcom.sys.cisco)
  • Re: starting transition fmp 6u to fmp 7: field definition question
    ... Professors really means the Course info, ... field of Type that specifies Student, Program Assistant, Professor. ... acccess to the Course_Professor database, and not the other ones in Web ... connection to a parent record. ...
    (comp.databases.filemaker)
  • Re: KirbyBase
    ... I'm an Object Guy and Jamey is a Database Guy. ... That requires the table name and key field name to be specified ... I suppose it would in effect be embedding an array where all the ... that is) might compress by a factor of 10 or more. ...
    (comp.lang.ruby)
  • Re: using BLOB objects and ...
    ... while saving the array object to the database which is ok but while ... convert it back to object of 4 dimention boolean array which will be ... will let you store your 4 dimensional boolean array in it. ... You may have to modify my suggestion ...
    (comp.lang.java.programmer)