Gossamer Forum
Home : Products : DBMan : Customization :

Record dependant field

Quote Reply
Record dependant field
Hi,
I have a database for hotels, and the users login with their userid, and I was wondering if it would be possible to create a drop down menu with options depending on that user (the options will be room types)? I have tried creating a 2nd .db file called roomtype.db where the 1st field is always the userid, and every field after is a room type. i.e. user001|single|double|twin
I have added a sub called build_select_field_from_other_db but for some reason the select field just shows the userid! Anyone know what i'm doing wrong? I can post the code if you want.
Reagrds
Ben

Quote Reply
Re: Record dependant field In reply to
The code: -
sub build_select_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, $fieldnum1, $fieldnum2, @lines, $line, $output);
my ($fieldnum, $found, $i) = 0;
$db_other_file_name = 'roomtype.db';
$name || ($name = $column);

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

# The number of the field in the other .db file that holds the values you want in your select field
$fieldnum2 = 2;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i;
$found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}
open (DB, "<$db_other_file_name") or &cgierr("Error in build_select_field_from_other_db. 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[$fieldnum1] eq $db_userid) {
if (!(grep $_ eq $fields[$fieldnum2], @selectfields)) {
push (@selectfields, $fields[$fieldnum2]);
}
}
}
close DB;

$output = qq|<SELECT NAME="$column" MULTIPLE SIZE=$size><OPTION>---|;
foreach $field (sort @selectfields) {
$selected = 0;
foreach $value (@values) {
if ($value eq $field) {
$output .= "<OPTION SELECTED>$field";
$selected = 1;
}
}
unless ($selected) {
$output .= "<OPTION>$field";
}
}
$output .= "</SELECT>";
return $output;
}