PerlJunkie45 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w ################ # Ray Espinoza # version: 0.1 # 6/29/04 ################# use strict; use DBI; use CGI qw(:standard); my ($pool, $host, $vip, $rule); ############## # Start HTML # ############## print header (), start_html (-title => "Rule Change Tool", -bgcolor => "#6666CC +", -text => "black"), h2("Rule Change Tool"); ######################## # grab database handle # ######################## my $dbh = &connect; ############## # main logic # ############## my $view = lc (param("view")); if($view eq "") { show_pools($dbh); } ######## # SUBS # ######## ################ sub show_pools { ################ my $dbh = shift; my $value = "pool"; my $poollist_ref = get_lookup_values($dbh, $value); print strong ("Resonate Rule Entry Form"), start_form (-action => url ()), table ( Tr ( td ("Pool: "), td (popup_menu (-name => "pool", -values =>$poollist_ref)) ), Tr ( td ("Hosts: "), br (), td (popup_menu (-name => "hosts", -values => [""])) ), Tr ( td ("VIP: "), td (popup_menu (-name => "vip", -values => ["", "home", "www"], -default => [""], -override => 1)) ), Tr ( td ("Rule: "), td (popup_menu (-name => "rule", -values => ["", "test", "test1", "test2", "test3"], -default => [""], -override => 1)) ), ), br (), submit (-name => "choice", -value => "Submit"), end_form (); } ####################### sub get_lookup_values { ####################### my ($dbh, $query) = @_; my ($sth, @val, $label_ref); $sth = $dbh->prepare(qq{ SELECT DISTINCT $query from table ORD +ER by $query }); $sth->execute (); # check whether or not query returns a label column $label_ref = {} if $sth->{NUM_OF_FIELDS} > 1; while (my @row = $sth->fetchrow_array ()) { push (@val, $row[0]); $label_ref->{$row[0]} = $row[1] if $label_ref; # add +label map entry } $sth->finish (); return (wantarray () ? (\@val, $label_ref) : \@val); } ############# sub connect { ############# use DBI; my ($dbh, $sth, $count); $dbh= DBI->connect("DBI:mysql:host=localhost;database=database","datab +aseuser","databasepassword",{PrintError => 0, RaiseError => 1}); return $dbh; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ideas for Logic to fill out this form
by BUU (Prior) on Jun 28, 2004 at 23:20 UTC | |
|
Re: Ideas for Logic to fill out this form
by borisz (Canon) on Jun 28, 2004 at 22:51 UTC | |
|
Re: Ideas for Logic to fill out this form
by clscott (Friar) on Jun 29, 2004 at 15:35 UTC | |
by PerlJunkie45 (Initiate) on Jun 29, 2004 at 16:07 UTC |