Gossamer Forum
Home : Products : DBMan : Discussions :

Re: Codes for different Options

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;
}

Subject Author Views Date
Thread Codes for different Options bjblackmore 4117 Nov 1, 2000, 6:18 AM
Thread Re: Codes for different Options
AstroBoy 4029 Nov 1, 2000, 3:01 PM
Post Re: Codes for different Options
bjblackmore 4012 Nov 2, 2000, 2:15 AM
Post Re: Codes for different Options
bjblackmore 3992 Nov 2, 2000, 2:26 AM
Post Re: Codes for different Options
bjblackmore 4030 Nov 2, 2000, 2:50 AM
Thread Re: Codes for different Options
bjblackmore 4001 Nov 2, 2000, 7:56 AM
Post Re: Codes for different Options
bjblackmore 3998 Nov 2, 2000, 9:07 AM