Okay. I think I got it.
In db.cgi, change
sub build_select_field_from_db
to the following:
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 | | ($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);
++$count{$fields[$fieldnum]};
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 .= qq|<OPTION SELECTED VALUE="$field">$field ($count{$field})|) :
($output .= qq|<OPTION VALUE="$field">$field ($count{$field})|);
}
$output .= "</SELECT>";
return $output;
}
Be sure to delete the space between the two | characters above that the forum software inserts.
In html_record_form (or, in your case, since we've talked on the phone, html_search_form), where you want to print out your select field, use
|;
print &build_select_field_from_db("
City",$rec{'
City'}");
print qq|
and then go on with printing your form.
Change
City to the exact name of your field.
This will make a select field that has only cities that are currently in the database.
------------------
JPD