Here is the code from a page that creates a select box list from records in a database:
<center> <table width=450 CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR="#FFFFf +f"> <tr><td><img src="http://lender-reviews.com/img/logo.png"> <br> <P align=center><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", "record-nu +mber", "modify"); print qq|</center> <P><INPUT TYPE="HIDDEN" NAME="modify_form_record" VALUE="1"> <center><INPUT TYPE="SUBMIT" VALUE="Modify"> <INPUT TYPE="RESET" VA +LUE="Reset Form"></center> </FORM> $html_menu $html_footer </font> </td></tr> </table> </center>
The select box output looks like this:
<P> <FORM ACTION="http://lender-reviews.com/cgi/dbmod.cgi/lender/lynn909 +67.htm" METHOD="GET"> <P><center><SELECT NAME="modify"><OPTION>---<OPTION>1ST ALLIANCE LE +NDING, LLC<OPTION>1ST COMMONWEALTH BANK OF VIRGINIA<OPTION>1ST MARYLA +ND MORTGAGE CORPORATION<OPTION>A PLUS MORTGAGE SERVICES INC<OPTION>AC +CESS 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" VA +LUE="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_na +me. 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')

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.

Randall Marquis


In reply to Help syntax? by randallmarquis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.