Hallo perlmonks,
I am using the following code in order to read the columns of a table in my sql database and then create a list of checkboxes. The problem is that when I try to modify the select statement in order to get the rows of a column, I just get the column name instead of all the rows. Any idea why this is happening?
Also after solving that I want to create a select statement including oly the checked checkboxes. any hint on how to achieve that would be extremely usefull
Thank everyone in advance for their help
#!/usr/bin/perl
use DBI;
use CGI ':standard';
use strict; use warnings;
my $q= CGI->new();
print header, start_html('Advanced Search');
# Connect to the database
my $dbh = DBI->connect('DBI:mysql:mirnas', 'root', 'bi0u90ee')
or die "Couldn't open database: $DBI::errstr; stopped";
# Getting all the column names and creating checkboxes for them
my $table = '07_11_09';
my $sth = $dbh->prepare("SELECT * from $table where 1=0); #this works!
+!!
my $sth = $dbh->prepare("SELECT mirna FROM $table ");
#this doesn't , it only displays the column name, not every row in the
+ column !!!!!
$sth->execute;
my @cols = @{$sth->{NAME}}; # or NAME_lc if needed
$sth->finish;
#printing the checkboxes
print
checkbox_group(-name=>'fields_to_search',
-values=>\@cols # Your array above
);
#storing the parameters from the checkboxes
my @fields_to_search=param('fields_to_search');
#creating the submit boxes
print'<FORM
ACTION="http://sirocco/cgi-bin/advanced_search.pl"
METHOD="POST">'; #here it submits the sel
+ected parameters to a search form
print br, '<INPUT TYPE = "SUBMIT"VALUE="Click To Submit">';
print '<INPUT TYPE="RESET"VALUE=Clear>';
print '</FORM>', end_html;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.