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

Quote Reply
Re: Getting data from another file! In reply to
Hi Ben, I'm having a tough time following what you are doing. Would you be able to save your files as text files and upload them to an area of your server where they can be viewed via the web. If needed, you can use the "Send Private" option at the top of the forum to send me a message (using my forum name) with the url where the files can be viewed.

Quote Reply
Re: Getting data from another file! In reply to
Hi Ben, I'm not able to view the files while they're in the cgi-bin - can they be moved to an area accessible via the web?

Quote Reply
Re: Getting data from another file! In reply to
Hi,
Did you recieve my private message? I put the files up in a private directory as text files!
Regards
Ben