in reply to Drop Down Selection From Database

This is really an HTML question:

use <SELECT> and <OPTION> tags.

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Replies are listed 'Best First'.
Re: Re: Drop Down Selection From Database
by michellem (Friar) on Jan 26, 2001 at 02:02 UTC
    It depends on what you want to do with this - if you are simply building a menu from available entries in a database - I'd put the entries in an array, then do a for loop like:
    print "<SELECT NAME=Company_Name>\n"; foreach (@company) { print "<OPTION VALUE=$_>$_\n"; } print "</SELECT>\n";
    However, if you want to do something more complex, like are editing that Company_Name field by using a drop down menu it's a bit more complex, because you've got to distinguish which option should be checked.
Re: Re: Drop Down Selection From Database
by koacamper (Acolyte) on Jan 26, 2001 at 00:47 UTC
    I understand how to use the <SELECT> and <OPTION> tags. My question is how do you pull the first entry, in the example database, to be the OPTIONs? Thank you
      You'll need to provide a little more information than this. In specific, what kind of database is it and what method are you using to pull it (eg, it's a MySQL database and I'm using DBI to interface with it)?
Re: Re: Drop Down Selection From Database
by Anonymous Monk on Jan 26, 2001 at 20:36 UTC
    something like this: not completely correct i think...
    
    use CGI;
    use DBI;
    use strict;
    
    my $q = new CGI;
    print $q->header();
    
    print "<html><form><select>\n";
    
    my $dbh = DBI->connect(&DSN, &USER, &PASS);
    
    my $sth  = $dbh->prepare("SELECT memberID, membername FROM members");
    
    $sth->execute();
    
    while( my ($memberID, $membername) = $sth->fetchrow_array() ) {
       print "<option value="$memberID">$membername \n";
    }
    
    
    
      it erased my formating... the first time.. something like this: not completely correct i think...
      
      use CGI;
      use DBI;
      use strict;
      
      my $q = new CGI;
      print $q->header();
      
      print "<html><form><select>\n";
      
      my $dbh = DBI->connect(&DSN, &USER, &PASS);
      
      my $sth  = $dbh->prepare("SELECT memberID, membername FROM members");
      
      $sth->execute();
      
      while( my ($memberID, $membername) = $sth->fetchrow_array() ) {
         print "<option value="$memberID">$membername \n";
      }