Please help solve this problem. For DBMan the following subs are used to have people save their favorites records into a separate database. Saving to the database works fine.
The problem is then in reading the file (sub view_favorites) and only returning the exact record IDs saved for each user.
A sample of the favorite.db looks like:
534-jackstraw|28-Mar-2002
494-jackstraw|28-Mar-2002
269-jackstraw|28-Mar-2002
614-lchiang|28-Mar-2002
1062-oldmoney|25-Apr-2002
649-kjellkk|07-May-2002
114-omegadm|15-May-2002
6-oldmoney|15-May-2002
What is happening is on the single digit record IDs such as # 6. It will then display all records containing the number 6.
Any help on getting sub view_favorites to display the exact record IDs would be appreciated.
sub add_to_favorites {
#---------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
LINE: while (<FAVE> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[0] eq "$in{$db_key}-$db_userid") {
$message = "That listing is already in your favorites list";
}
}
close FAVE;
unless ($message) {
open (FAVE, ">>$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) {
flock(FAVE, 2) or &cgierr("Unable to get exclusive lock on $db_favorites.\nReason: $!");
}
$date = &get_date();
print FAVE "$in{$db_key}-$db_userid|$date\n";
close FAVE; # automatically removes file lock
$message = "Listing added to favorites list";
}
&html_favorite_success($message);
}
sub view_favorites {
# --------------------------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in view_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
@flines = <FAVE>;
close FAVE;
foreach $fline (@flines) {
@data = &split_decode($fline);
if ($data[0] =~ /(.+)-$db_userid/) {
$in{$db_key} .= "$1|";
}
}
chop $in{$db_key};
$in{'re'} = 1;
$in{'ww'} = 1;
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure("No favorites on file");
}
}
Unoffical DBMan FAQ
http://creativecomputingweb.com/dbman/index.shtml/
The problem is then in reading the file (sub view_favorites) and only returning the exact record IDs saved for each user.
A sample of the favorite.db looks like:
534-jackstraw|28-Mar-2002
494-jackstraw|28-Mar-2002
269-jackstraw|28-Mar-2002
614-lchiang|28-Mar-2002
1062-oldmoney|25-Apr-2002
649-kjellkk|07-May-2002
114-omegadm|15-May-2002
6-oldmoney|15-May-2002
What is happening is on the single digit record IDs such as # 6. It will then display all records containing the number 6.
Any help on getting sub view_favorites to display the exact record IDs would be appreciated.
sub add_to_favorites {
#---------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
LINE: while (<FAVE> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[0] eq "$in{$db_key}-$db_userid") {
$message = "That listing is already in your favorites list";
}
}
close FAVE;
unless ($message) {
open (FAVE, ">>$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) {
flock(FAVE, 2) or &cgierr("Unable to get exclusive lock on $db_favorites.\nReason: $!");
}
$date = &get_date();
print FAVE "$in{$db_key}-$db_userid|$date\n";
close FAVE; # automatically removes file lock
$message = "Listing added to favorites list";
}
&html_favorite_success($message);
}
sub view_favorites {
# --------------------------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in view_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
@flines = <FAVE>;
close FAVE;
foreach $fline (@flines) {
@data = &split_decode($fline);
if ($data[0] =~ /(.+)-$db_userid/) {
$in{$db_key} .= "$1|";
}
}
chop $in{$db_key};
$in{'re'} = 1;
$in{'ww'} = 1;
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure("No favorites on file");
}
}
Unoffical DBMan FAQ
http://creativecomputingweb.com/dbman/index.shtml/