Solved

Populate Drop Down List with Values from CSV DB

Posted on 1998-10-28
4
449 Views
Last Modified: 2013-12-25
I'm using Front Page 98 to create a webpage.  I need a Drop Down List to be populated with values from a .CSV database.  I use Perl 5 to write CGI scripts sucessfully on other pages on this same site.  Anyone know how to do this?
0
Comment
Question by:EvanL
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
sax earned 110 total points
ID: 1829320
hi evan

You could load the data from the .CSV file into an associative array using perl and then populate the <select> statement from the arrays.

Following is an example:

;here is how to load the data into the arrays

 while (<DATA>) {
                ($userid,$username,$pword,$supplier,$email) = split(/,/);
                $suppl{$supplier} =  $username;
        }
        close DATA;      

;display the data as a drop down list

print "<tr><td>Select the Supplier:";
print "<td><select name=\"supplier\">";
while (($key, $value) = each %suppl) {
        print "<option value=$key>$value";
        print "\n";
    }
print "</select></table>";        

%suppl is the assoc array that holds the key and the values for the drop down list.

-HTH
sax
0
 
LVL 1

Author Comment

by:EvanL
ID: 1829321
I'm new to Perl 5 so lemme be specific so the code you post can reflect it.  The field name is "Last Name" in the .csv database and there are about 300 records there - each with a "Last Name" field filled.  So the drop down list would have to be filled with each record from the database.

I've increased the points so you will repost.. Thanks!
0
 
LVL 1

Author Comment

by:EvanL
ID: 1829322
Doh!  Also, what code appears in the .cgi file and which goes in the .html file?
0
 

Expert Comment

by:sax
ID: 1829323
I am assuming that each line in the file has one last name listed, as shown below:

SMith
Patrick

etc..

and you have enough knowledge of HTML that is being shown here.
============
The entire HTML file will have to generated by the perl script
===========
$inputdata = "csvfile";
open(DATA, $inputdata);

while (<DATA>) {
                    ($lastname) = split();
                    push $suppl, $lastname;
            }

;display the data as a drop down list
 ;print table

    print "<table>";
    print "<tr><td>Select the last name";
    print "<td><select name=\"lastname\">";
    foreach $element ($suppl) {
            print "<option value=$element>$element";
            print "\n";
        }
    print "</select></table>";          
       

-sax
                   
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question