List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:May 7 2000 11:36pm
Subject:Drop Down Menu with defined Data:
View as plain text  
Simple question on Mysql and drop down menus from a table in the
database.

I am creating a form for gathering information on campus and need two
drop down menus in this form:
The first will be a list of colleges and schools and the second drop
down menu will be the list of departments relating to the first drip
down menu box:

Should I create a defined set in mysql ? such as a table with id,
college and departments
insert all the data on the command line and then when I display the form
use a fetchrow array?

Or should I do what I have done in the past and simply use a javascript
for relational drop down menus and just have all the colleges and
departments listed in the javascript, which seems the long way around.
The Mysql way sounds the best, because then I can make changes
dynamically.

Can't I write something like this:  Would the following do what I need
and will it work?

##The first drop down menu
## "list"  will be the name of the table in the database.
print "Please Select your College";
my $sth = $dbh->Query("select college from list ")
$sth->execute;
my @arr=();
while (@arr = $sth->fetchrow)
{
($college)=@arr;
$college = $college;
print $query->popup_menu (-name=>'COLLEGE',
                                        -"values"=>['$college',

],
-default=>$defaultcollege);      # This would be needed when updating
data?
}
## second drop down menu
print "<BR>
print "Please Select the Department</td><td>";
my $sth2 = $dbh->Query("select dept from list where college="$college"
")
$sth2->execute;
my @arr=();
while (@arr = $sth2->fetchrow)
{
($dept)=@arr;
$dept = $dept;
print $query->popup_menu (-name=>'DEPT',
                                        -"values"=>['$dept',

],
-default=>$defaultdept);
}

It is obvious that I don't do much coding and I'm trying to learn, so
any assistance would be fantastic.
Thanks in advance for your help.

Thanks,

Douglas

Thread
Drop Down Menu with defined Data:Douglas Brantz8 May
  • Re: Drop Down Menu with defined Data:Douglas Brantz8 May
    • RE: Drop Down Menu with defined Data:benjamin-weiss8 May
      • Re: Drop Down Menu with defined Data:Douglas Brantz8 May
        • Re: Drop Down Menu with defined Data:Christopher R. Jones8 May
        • RE: Drop Down Menu with defined Data:benjamin-weiss8 May