This may already be in your script, even though it is not mentioned anywhere. Open db.cgi and do a search for
sub build_select_field_from_db
If it's there, ignore the next part of this and go to the end of this message to find out how to use it.
If it's not there, add the following subroutine to db.cgi:
Code:
sub build_select_field_from_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;
$name or ($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_file_name") or &cgierr("unable to open $db_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="$name"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}
To use this, in the place where you want it to print the select field, enter
Code:
|;print &build_select_field_from_db("FieldName","$rec{'FieldName'}"); print qq|
replacing FieldName with the name of the field you want to have in your select list.
------------------
JPD