Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Populate Drop Down List with Values from CSV DB

Posted on 1998-10-28
4
Medium Priority
?
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
sax earned 220 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 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