Background
I am trying to do something similar with a more complicated problem so here is an example similar to what i am trying to achieve.
I am pulling some data from a table and trying to lay it out in an particular order. To be spacific as you can see in my example sql(prepare) statement, i am pulling in info about a school and ordering it by minor.
here is a sample of the code

$SQL_report = "select distinct student_id, student_name, student_address, student_gpa, college from SCHOOL where MINOR = 'CS' ORDER BY student_id"; $sth->execute; while (@row = $sth_report->fetchrow_array) { $student_id = (defined $row[0]) ? $row[0] : ''; $student_name = (defined $row[1]) ? $row[1] : ''; $student_address = (defined $row[2]) ? $row[2] : ''; $student_gpa = (defined $row[3]) ? $row[3] : ''; $college = (defined $row[4]) ? $row[4] : ''; ## Make our html look better if no data. $student_id = " " if ($student_id eq ""); $student_name = " " if ($student_name eq ""); $student_major = " " if ($student_address eq ""); $student_gpa = " " if ($student_gpa eq ""); $college = " " if ($college eq ""); } # End of while

Problem
Everything is working just fine on the DBI side and i can get data which at present looks something like this.

id, name, addrss, major, gpa, college id, name, addrss, major, gpa, college id, name, addrss, major, gpa, college id, name, addrss, major, gpa, college
and is ordered too by id_number. which is exactly what it should be like, BUT
I need to somehow sort this incomming data by college. Example:
BUSINESS SCHOOL id, name, address, gpa id, name, address, gpa id, name, address, gpa ENGINEERING id, name, address, gpa id, name, address, gpa id, name, address, gpa NURSING id, name, address, gpa id, name, address, gpa id, name, address, gpa
I have tried to use a few different ways using loops but i cant seem to get it to come out right. As always any input will go a long ways....
Thanks

Edit by dws for tag cleanup


In reply to Sorting data pulled in by DBI by data67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.