Gossamer Forum
Home : Products : DBMan : Discussions :

Getting data from another file!

Quote Reply
Getting data from another file!
Hi,
I read a post on LoisC's web site about getting values out of another db file. I'm trying to use it but it seems to be giving me problems. I have pasted the code below so you can see which one I mean. I would like a user to be able to logon and depending on that user id, different options will be displayed in a drop down menu. However at the moment this seems to ignor the other file and pull its information out of the default.db. The other file is a list of rooms types for customers, and depending on the userid you get different room types. i.e.
user1|single|double
user2|single|double|family
user3|double
Is there away to do this? It seems like your code should work! But I connot figure out why it is not.

sub build_limited_multiple_select_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from an external database.
# Parameters are the column to which the value will be written -- $column
# a default value -- $value
# the height of the select field -- $size (optional)
my ($column, $value, $size) = @_;
my (@fields, $field, @selectfields, $selected, $fieldnum1, $fieldnum2, @lines, $line, $output, $found, @values);
$size or ($size = 3);
@values = split (/\Q$db_delim\E/,$value);
# Be sure to change the following to match your database
# The name of the other .db file
$db_other_file_name = $db_script_path . "/roomtypes.db";
# The number of the field in the other .db file that holds the
# values you want in your select field
$fieldnum1 = 1;
# The number of the field in the other .db file that holds the userid.
$fieldnum2 = 0;
# End of things to edit.
for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$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[$fieldnum2] eq $db_userid) {
if (!(grep $_ eq $fields[$fieldnum1], @selectfields)) {
push (@selectfields, $fields[$fieldnum1]);
}
}
}
close DB;
$output = qq|<SELECT NAME="$column" MULTIPLE SIZE=$size>|;
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;
}
Regards
Ben

Subject Author Views Date
Thread Getting data from another file! bjblackmore 2972 Oct 25, 2000, 7:27 AM
Thread Re: Getting data from another file!
Karen 2894 Oct 25, 2000, 9:50 AM
Thread Re: Getting data from another file!
Karen 2851 Oct 27, 2000, 9:19 PM
Post Re: Getting data from another file!
bjblackmore 2816 Nov 3, 2000, 9:06 AM