Gossamer Forum
Home : Products : DBMan : Installation :

Is it possible to register the number of hits of a record??

Quote Reply
Is it possible to register the number of hits of a record??
I wonder, if I can hold the number of times, a record is viewed, only in the sub_long mode.
Quote Reply
Re: Is it possible to register the number of hits of a record?? In reply to
You would have to modify the record within the "long record" subroutine.

You could do it like this:

Code:
open (DB, "<$db_file_name") or &cgierr("error in modify_records.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
++$rec{'Count'};
$output .= &join_encode(%rec);
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("error in modify_records.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB;

I would add this directly to the html.pl file, in the "long record" subroutine, either before or after the page prints out.

You would need to change the "$rec{'Count'}" variable above to whatever the name of your counter field is.

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