Solved

Populate Drop Down List with Values from CSV DB

Posted on 1998-10-28
4
438 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now