Here is the code from a page that creates a select box list from records in a database:
<table width=450 CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR="#FFFFff">
<tr><td><font face=Arial size=2>Pick which Company you wish to modify:
<P>
<FORM ACTION="$db_script_url" METHOD="GET">
<P><center>|; print &build_select_field_from_db ("name", "", "modify"); print qq|</center>
<P><INPUT TYPE="HIDDEN" NAME="modify_form_record" VALUE="1">
<center><INPUT TYPE="SUBMIT" VALUE="Modify"> <INPUT TYPE="RESET" VALUE="Reset Form"></center>
</FORM>
$html_menu
$html_footer
</font>
</td></tr></table>
The select box 'output' looks like this:
<P>
<FORM ACTION="http://lender-reviews.com/cgi/dbmod.cgi/lender/lynn90967.htm" METHOD="GET">
<P><center><SELECT NAME="modify"><OPTION>---<OPTION>1ST ALLIANCE LENDING, LLC<OPTION>1ST COMMONWEALTH BANK OF VIRGINIA<OPTION>1ST MARYLAND MORTGAGE CORPORATION<OPTION>A PLUS MORTGAGE SERVICES INC<OPTION>ACCESS NATIONAL MORTGAGE CORPORATION<OPTION>ACHIEVA CREDIT UNION<OPTION>ACOPIA LLC</SELECT><P><INPUT TYPE="HIDDEN" NAME="modify_form_record" VALUE="1"> <br>
<center><INPUT TYPE="SUBMIT" VALUE="Modify"> <INPUT TYPE="RESET" VALUE="Reset Form"></center><br>
</FORM>
The routine that creates the content is "build_select_field_from_db"
Here is the routine in full:
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;
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: $!");
@lines = <DB>;
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^#/) { next LINE; } # Skip comment lines.
if ($line =~ /^\s*$/) { next LINE; } # Skip Blank Lines.
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
if ($name) { $output = qq|<SELECT NAME="$name"|; }
else { $output = qq|<SELECT NAME="$column"|; }
$output .= "><OPTION>---";
foreach $field (sort @selectfields) {
if ($field eq $value) {
$output .= "<OPTION SELECTED>$field";
}
else {
$output .= "<OPTION>$field";
}
}
$output .= "</SELECT>";
return $output;
}
And therein lies my problem. I need the select box content changed to include the value of the database key, which is the first column in the database (known as 'record-number') also known as column '0' (zero).
This line: $output .= "<OPTION>$field"; Needs to be changed to this somehow: $output .= "<OPTION value=\"record-number\">$field";
Where the above 'record-number' actually pulls the data from that record.
Here's what a line out of the database looks like:
5111|ACOPIA LLC|BRANT PHILLIPS|306 NORTHCREEK BLVD STE
The actual desired outcome is to create a 'SELECT' tag that looks like this:
<OPTION value="5111">ACOPIA LLC
Simple? I don't know... I tried $db_key but it only returned the name of the field (record-number) and not the data. I tried $record-number and that only returned '-number' but not the data.
Stumped... and standing by all day today for ideas.
Randall Marquis