On May 12, Pam Derks said:
>I'm a newbie struggling to total up a web users survey for work. The
>HTML form is a separte document, which calls up the cgi script. I've
>been reading the CGI module and figured out how to get the key/value
>paris. Now, I want to tally the answers, i.e. 10 users choose question 2
>(Q2), I want it to show: Question2: 10
> sub get_total{
> my $query = @_;
Whoops, you did it right the first time.
my ($query) = @_;
> my(@values, $key);
> print "<H2>Here are the totals: </H2>";
> if ($value ($cgi->param('Q2') ne ' ')){
I'm not sure what that $value is doing there...
> $count2++;
> print ("Question2: $count\n");
You're incrementing $count2, but using $count?
> }
> }#end subroutine get_total
It might help if you 'use strict' in your program, to make sure you're
using the variables you think you are.
Also, it seems like you're looking for some sort of running total. For
this, you'll need a database of some sort to keep the counts for each
question. There are many possibilities to choose from.
use SDBM_File; # not BDSM_File ;)
use Fcntl; # for O_CREAT and O_RDWR constants
tie my(%db), SDBM_File => (
$filename,
O_CREAT | O_RDWR, # file flags
0666, # permissions
) or die "can't tie to $filename: $!";
for my $key ($cgi->param) {
$db{$key}++ if $cgi->param($key);
}
That might be how you would tally the results.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734