I think I have a solution to this that will work.
I'm assuming you want to count the values in one field -- that is, that one field can have one of several different options and you want to count how many of each option have been selected.
You'll need to know the number of the field that you're using -- not the name -- for this one. For this example, I'm going to count the entries in field 6. The possible entries are "Computer,Freebies, and Tutorials."
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;
$count_total = scalar(@lines);
@options = (
'Computer','Freebies','Tutorials');
foreach $line (@lines) {
@data = &split_decode($line);
++$count{$data[
6]};
}
When you want to print out the information, you would use
Code:
print "There are a total of $count_total entries in the database:<BR>";
foreach $option (@options) {
unless ($count{$option}) {
$count{$option} = "0";
}
print "$option ($count{$option})<BR>";
}
Naturally, you'll change everything that is in bold print above to match your database.
This is untested, but I think I at least found all my syntax errors. Please let me know what happens.
------------------
JPD