Gossamer Forum
Home : Products : DBMan : Discussions :

Cross Referance with 2nd Database

Quote Reply
Cross Referance with 2nd Database
Hi,
I'm trying to access a 2nd database, and cross referance the 1st field in it with the userid, and pull the 2nd field into a dropdown menu. I'm using the following code, but I keep getting errors, can anyone see why? (the name of the db_other_file_name is in the config file)

sub build_select_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.

my ($column, $value) = @_;
my (@fields, $field, @selectfields, $fieldnum1, $fieldnum2, @lines, $line, $output);

# The number of the field in the other .db file that holds the values you want in your select field
$fieldnum1 = 2;

# The number of the field in the other .db file that holds the userid.
$fieldnum2 = 1;

open (DB, "<$db_other_file_name") or &cgierr("unable to open $db_other_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum2] eq $db_userid) {
if (!(grep $_ eq $fields[$fieldnum1], @selectfields)) {
push (@selectfields, $fields[$fieldnum1]);
}
}
}
close DB;

$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}

Any help greatly appreciated.
Ben