Gossamer Forum
Home : Products : DBMan : Customization :

Adding totals subroutine/changing order

Quote Reply
Adding totals subroutine/changing order
Hello Everyone,

I've added a subroutine (found on this site) to my database that totals a data set. However, these totals are returned in alphabetical order and I like them to be ordered by the classifcation field in the database. Here are routines I have in the html.pl and db.cgi files.

HTML.pl subroutine
sub view_html_totals {
# --------------------------------------------------------

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: View Totals.</title>
</head>

<body bgcolor="#DDDDDD">
<FONT face="arial,verdana,helvetica" color="navy" size="-1">
<div align="left">
<p><br>
COUNT SUMMARY<br>
<p>

|;

&view_totals;
foreach $Species (sort keys %total) {
print qq|$Species - $total{$Species}<br>|;
}
print qq|<br>Total Bird Count = $grand_total|;
print qq|
</div>
</font>
</body>
</html>
|;
}

db.cgi subroutine

sub view_totals {
# --------------------------------------------------------

my ($status,@hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);

for (0 .. $numhits - 1) {
my (%rec) = &array_to_hash($_, @hits);
$total{$rec{'Species'}} += $rec{'Number'};
$grand_total += $rec{'Number'};
}
}

Also here is how it is called in the (layout code not included).

sub html_view_success {
# --------------------------------------------------------
Your search returned <b>$db_total_hits</b> matches.</font>

|;
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

# Go through each hit and convert the array to hash and send to
# html_record for printing.
print "<table>";
for (0 .. $numhits - 1) {
++$rec_count;
if ($rec_count%2) {
print "<tr>\n";
}
print "<td>";
&html_record (&array_to_hash($_, @hits));
print "</td>";
unless ($rec_count%2) {
print "</tr>\n";
}
}
# this section prints out a blank cell in case there are an odd number of records returned
unless ($rec_count%2) {
print "<td>&</td></tr>\n";
}
print "</table>";

if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

print qq|
<p>
<table border=0 cellpadding=2 cellspacing=1 width="100%" valign=top>
<tr><td>

|;
&view_html_totals;
&html_short_search(); print qq|

I've also added the appropriate code in the sub main.

As I said ... it all works, however, the the data is returned alphabetically and I like the data order by the "Classification" field in the database.

Thanks so much,

Keith F. Saylor
Subject Author Views Date
Thread Adding totals subroutine/changing order ksaylor 1721 Sep 14, 2001, 4:24 PM
Thread Re: [ksaylor] Adding totals subroutine/changing order
LoisC 1635 Sep 15, 2001, 2:57 PM
Thread Re: [LoisC] Adding totals subroutine/changing order
ksaylor 1634 Sep 16, 2001, 6:07 PM
Post Re: [ksaylor] Adding totals subroutine/changing order
LoisC 1616 Sep 18, 2001, 6:36 PM