Gossamer Forum
Home : Products : DBMan : Installation :

countables and tallies

Quote Reply
countables and tallies
I was wondering if this has been implemented or not -- I would like to have a running tally of all records available and if it is also possible to have running tallies for some of the categories.

Yeah, I know that I should view the records but I'm in a rush today and don't have the time to look through a bunch of strange links. sorry, for being lazy today.
Quote Reply
Re: countables and tallies In reply to
You want to count the total number of records and the number of records that have the same value in a field. Is that correct?

Yes, that's been discussed quite a bit. But I'll go over it again.

First, you need to get the field number you want to count. If, for example, you wanted to know how many records were in each different category in the "Category" field, you would use the number of the "Category" field. For my purposes, I'm going to use the number 6, because I like that number. Smile I'll put it in bold print so you'll be able to find where to change it.

Most people print counts on their html_home page, to give users an idea of what's in the database. If that's what you want to do, this code will go into html_home, right at the beginning. If not, put it at the beginning of whatever subroutine matches the page you want to print it out on.

Code:
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
foreach $line(@lines) {
if ($line =~ /^$/) { next; }
if ($line =~ /^#/) { next; }
@data = split /$db_delim/, $line;
++$count{$data[6];
++$total_count;
}

When you want to print out your data, you can use something like:

Code:
print "There are $total_count records in the database.<BR>"
foreach $key (sort keys $count) {
print "$key: $count{$key}<BR>";
}


------------------
JPD







[This message has been edited by JPDeni (edited July 08, 1999).]
Quote Reply
Re: countables and tallies In reply to
Thanks JP,

Yes, 6 is a cool number as well as earl grey.

Smile