That could possibly be happening with the exclusion of the following line in the
build_update_ratings:
Code:
$values[$db_votes] = $values[$db_votes] + $votes{$id};
Although if you are using the crontab method...you cannot use the buildrate.cgi file. If you are using the crontab method...do NOT use the buildrate.cgi script! Also, make sure that you have not included the
sub build_update_rating routine and also the call for this routine (
&build_update_rating, in the
rate.cgi script. DO NOT mix up these methods...Use one of them...not all.
BTW: The id files in the $db_rates_path should be deleted upon updating the ratings. However, the database file and bak file
should NOT be deleted. If you are not on a UNIX server, then the problem could be with the chmod 666 codes.
Are you on a UNIX server?? Replace the
sub build_update_ratings with the following codes:
Code:
sub build_update_ratings {
# --------------------------------------------------------
# Updates the ratings of each link.
#
# Let's collect the ratings.
my ($id, %rating, %votes, @values, $input);
opendir (HITS, $db_rates_path) or &cgierr ("unable to open ratings directory: $db_rates_path. Reason: $!");
while (defined ($id = readdir HITS)) {
next unless ($id =~ /^\d+$/);
open (HIT, "$db_rates_path/$id") or &cgierr ("unable to open rating counter: $db_rates_path/$id. Reason: $!");
my $input = <HIT>;
chomp $input;
($votes{$id}, $rating{$id}) = split /\s/, $input;
close HIT;
}
closedir HITS;
# Update the links database.
open (DB, "$db_file_name") or &cgierr ("unable to open links database: $db_file_name. Reason: $!");
open (DBTMP, ">$db_file_name.bak") or &cgierr ("unable to open temp links database: $db_file_name.bak. Reason: $!");
LINE: while (<DB> ) {
/^#/ and print OUT and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = split /\Q$db_delim\E/;
$id = $values[0];
if (exists $votes{$id}) {
$values[$db_rating] = (($values[$db_rating] * $values[$db_votes]) + $rating{$id}) /
($values[$db_votes] + $votes{$id});
$values[$db_rating] = sprintf ("%.2f", $values[$db_rating]);
$values[$db_votes] = $values[$db_votes] + $votes{$id};
print "\tUpdating rating to $values[$db_rating] for link id $id\n";
}
print DBTMP &join_encode(&array_to_hash(0, @values));
}
close DB;
close DBTMP;
if (-s "$db_file_name.bak" > 0) {
if (! rename ("$db_file_name.bak", $db_file_name)) {
print "\tCouldn't rename! Had to copy. Strange: $!\n";
open (DBTMP, ">$db_file_name") or
&cgierr ("unable to open links database: $db_file_name. Reason: $!");
open (DB, "$db_file_name.bak") or
&cgierr ("unable to open temp links database: $db_file_name.bak. Reason: $!");
while ( ) { print DBTMP; }
close DB;
close DBTMP;
}
else { chmod 0666, $db_file_name; }
}
else {
&cgierr ("Error building! Links database is 0 bytes!");
}
# Delete the ratings.
foreach (keys %votes) {
unlink ("$db_rates_path/$_") or &cgierr ("unable to remove rating: $db_rates_path/$_. Reason: $!");
}
}
Hope this helps.
Regards,
------------------
Eliot Lee....
* Check Resource Center
* Search Forums
[This message has been edited by AnthroRules (edited February 20, 2000).]