For my homepage http://www.cool-movie-trivia.com I wanted to track how many users took the quiz and what the average score was. I finally cobbled together a little hack to do it and thought nothing more of it, but recently have had a couple of people ask how I did it so here's the email I sent them. The code is probably too sloppy to be of use to anyone, but if anyone wanted to try to implement it... here's the email I sent to the guys who enquired anyways. Cal Bond ---------------- Hi- Yeah I kind of just cut and pasted together the add-on. I'm not much of a programmer, but below is what I did. Basically in the results folder I created another data file I called average.data. Then in the program where they set a couple of counters to zero, I added these: $total_users= "0"; $total_score="0"; Then, when they go through the results line by line in the "Edit the Results Data" section, towards the end I added this little increment to get the total users count each time the file is updated: print RESULTS "$sorted_row"; $total_users++; #(<<<>) open (average, "$results_average") || &CgiDie ("I am sorry, but I was not able to open the average score data file in the Edit the Results Data File routine. The value I have is $results_database. Would you check the path and the permission."); $total_score_old=; @average=; close (average); $total_score=$total_score_old+$number_of_correct_answers; if ($total_users > 0) { # don't divide by zero! $avg_rating = sprintf'%.2f',($total_score / $total_users); } else { $avg_rating = 0; } @average[0]="$title|$avg_rating|$total_users\n"; open (average, ">$results_average") || &CgiDie ("I am sorry, but I was not able to open the average score data file in the Edit the Results Data File routine. The value I have is $results_database. Would you check the path and the permission."); print average "$total_score\n"; print average @average; close (average); &ReleaseFileLock ("$lock_file"); (I moved the '&ReleaseFileLock ("$lock_file");' line of code from above to keep the file locked while it was writing to the average.data file as well to keep everything square and tidy) Then finally I added this html chunk at the top of the "Send client their report card" section
Your Score Average Score Total Participants
$number_of_correct_answers out of $total_number_of_questions $avg_rating $total_users