Gossamer Forum
Home : Products : DBMan : Discussions :

Codes for different Options

Quote Reply
Codes for different Options
Hi,
Is it possible to select 1 thing from a drop down menu, but have dbman enter something else into the database? I.e. Have a drop down menu for room types with: - 'Single', 'Double', 'Family'. So if someone selects 'Single' a code is entered into the database which means single and if someone selects 'Double' a different code is entered.
Regards
Ben

Quote Reply
Re: Codes for different Options In reply to
Check out the following thread:
http://www.gossamer-threads.com/...ew=&sb=&vc=1

Good luck!

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Codes for different Options In reply to
Great thanks your a life saver! I owe you a beer mate! :)

Quote Reply
Re: Codes for different Options In reply to
Umm small problem now when I try to add a record I get Error: Unable to Add Record! I have 7 select fields, but only 1 of these need to have different values! All the other are just normal select fields!
Ben

Quote Reply
Re: Codes for different Options In reply to
OK don't worry problem fixed! in db.cgi I left sub build_select_field as normal then added your routine in as sub build_select_options_field! Then in default.cgi I left %db_select_fields alone and added %db_select_option_fields with the options, and referanced this in the html.pl! All works fine now! Thanks for your help mate! Like I said I owe you a beer!
Ben

Quote Reply
Re: Codes for different Options In reply to
This is working fine, thanks for the help! But I was wondering if there was away to get this info out of another file? This field is for room types! And depending on the user depends on which room types!
So if User001 logs in I want it to maybe show Single, Double, Twin
(each room type has a code which is why I needed the code to show a different value)
But if user002 logs in I might want to show Single, Twin, Suite!
I know how to do these 2 things separatly, (1. Show different values to what is entered in the database, and 2. Pull information out of another file) But I'm not sure if there is away to join them together.
Thanks again
Ben

P.S. You get a bottle of Bourbon this time!!

Quote Reply
Re: Codes for different Options In reply to
Do you think something like below might work? I've kinda hashed together the 2 sub routines! 1 for getting info out of a file, and yours for showing 1 value but entering another!

sub build_select_option_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $output, $op_text, $op_value);
my ($fieldnum, $found, $i) = 0;
$db_other_file_name = 'roomtype.db';
$name || ($name = $column);
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("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 (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (@fields) {
@option = split(/\|/, $field);
$op_text = @option[0];
$op_value = @option[1];
$op_text eq $value ?
($output .= "<OPTION SELECTED value=\"$op_value\">$op_text\n") :
($output .= "<OPTION value=\"$op_value\">$op_text");
}
$output .= "</SELECT>";
return $output;
}