Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: perl, DBI and CGI checkboxes

by spazm (Monk)
on Mar 22, 2010 at 15:53 UTC ( #830106=note: print w/ replies, xml ) Need Help??


in reply to perl, DBI and CGI checkboxes

yes.

In fact, there are lots of ways. You might want to consider a framework and an ORM layer to simplify your HTML and DB interaction. But here's a nice barebones solution in the vein of your original code.

See CGI for more information. ( http://search.cpan.org/~lds/CGI.pm-3.49/lib/CGI.pm )

#!/usr/bin/perl use DBI; use CGI; use strict; use warnings; my $q= CGI->new(); print $q->header(), $q->start_html(); # Connect to the database # See footnote 1 my $dbh = DBI->connect('DBI:mysql:mirnas', 'user', 'pass') or die "Couldn't open database: $DBI::errstr; stopped"; # Getting all the column names my $table = '07_11_09'; my $sth = $dbh->prepare("SELECT * FROM $table WHERE 1=0;"); $sth->execute; my @cols = @{$sth->{NAME}}; # or NAME_lc if needed $sth->finish; print $q->checkbox_group( -name=>'databases', -values=>[@cols], -linebreak=>'true', #-labels=>\%labels, #-attributes=>\%attributes ); print $q->end_html();


Comment on Re: perl, DBI and CGI checkboxes
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://830106]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-25 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls