Gossamer Forum
Home : Products : DBMan : Customization :

Catagory Count

Quote Reply
Catagory Count
Hi, in thread
http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000638.html
There was some code given that was used to setup a cout of countries like this:

Belgium (2)
France (3)
Luxembourg (0) or locations with 0 records can be omitted.

But when I tried to use the code to setup a catagory count. I get an error at ++total_count;
code:
open (DB, "<$db_default.db") or &cgierr("error in count. unable to open database: $db_default.db.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); } @lines = <DB>;
close DB; foreach $line (@lines) { chomp ($line);
@data = &split_decode($line);
++$count{$data[3]};

}

print qq|Parts list:<P><table>|;
foreach $catagory (%count) {
print qq|<tr><td>$catagory:</td><td>$count{$catagory}</td></tr>|;
}
print qq|<tr><td>Total:</td><td>$total_count</td></tr></table>|;
}

Did I modify this right?

Thanks!

------------------
Sherwin Sales@jse.net
Quote Reply
Re: Catagory Count In reply to
Now, I get:
Error Message : error in count. unable to open database: default.
Reason: No such file or directory

Code located at http://sherwingaddis.hypermart.net/cgi-bin/dbman/html.txt

Thanks

------------------
Sherwin Sales@jse.net
Quote Reply
Re: Catagory Count In reply to
Instead of

Code:
open (DB, "<$db_default.db") or &cgierr("error in count. unable to open database: $db_default.db.\nReason: $!");

try

Code:
open (DB, "<$db_file_name") or &cgierr("error in count. unable to open database: $db_file_name.\nReason: $!");


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





Quote Reply
Re: Catagory Count In reply to
I did that and still got the error so I took out the line. Now, I get nothing. I corrected my spelling of $Category to match what was in the default.cfg and matched the field number. The field number is 3. What else could you see?

THanks!

------------------
Sherwin Sales@jse.net
Quote Reply
Re: Catagory Count In reply to
It's the location of the code that is the problem. You have

Code:
print qq|Parts list:<P><table>|;
foreach $Category (%count) {
print qq|<tr><td>$Category:</td><td>$count{$Category}</td></tr>|;

in sub html_view_search before you print out the script header. You need to put it somewhere onto the actual page -- after the <body tag at least.

Another problem is that your <table> tag isn't closed anywhere. It might work on Internet Explorer, but nothing will show up on Netscape unless you close the <table>.

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







[This message has been edited by JPDeni (edited September 30, 1999).]
Quote Reply
Re: Catagory Count In reply to
Thanks for your help but.... It still does not show up! I got the problem with the total count solved. It was a missing $. Now it displays the total records in the system but I am trying to get it to list the number of Systems records (the third category) that are in the database. It will not list a count of those. Have made some changes but still can not stumble across the right code combonation. :-) The code is still listed at the same address. Help!

------------------
Sherwin Sales@jse.net
Quote Reply
Re: Catagory Count In reply to
I don't understand what you are doing. You have

Code:
<tr><td>Systems:</td><td>$count</td></tr>

I know this won't give you anything, because there is not a variable named $count defined anywhere.

If Systems is one of your items in field three that you are counting, you can use

Code:
<tr><td>Systems:</td><td>$count{'Systems'}</td></tr>

to print it out.

Is that what you want?[/code]
------------------
JPD





Quote Reply
Re: Catagory Count In reply to
What I want is Category printed and the number of times it is in the database i.e.
Systems (15)
Hard Drives (150)

------------------
Sherwin Sales@jse.net
Quote Reply
Re: Catagory Count In reply to
Thank you!! That did it for me. I can get the rest.