in reply to perl, DBI and CGI checkboxes

hi, If I understand you correctly you want to read the table headers of a table in the DB (or even describe the table ;) into an array and for every entry in the array add a checkbox, then on reading if that entry is checked you wish to use the associated field in the SELECT statement?

That is a spec in itself, in CGI you can use a checkbox_group as follows

print checkbox_group(-name=>'fields_to_search', -values=>\@cols # Your array above );
And when processing
@fields_to_search=param('fields_to_search');

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: perl, DBI and CGI checkboxes
by gogoglou (Beadle) on Mar 24, 2010 at 12:48 UTC
    Thanks a lot for the answer, it did work Now I want to change the script so instead of selecting the columns, selecting the rows so my script looks as follows:
    #!/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 # See footnote 1 my $dbh = DBI->connect('DBI:mysql:mirnas', 'root', 'pass') 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;"); $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">'; print br, '<INPUT TYPE = "SUBMIT"VALUE="Click To Submit">'; print '<INPUT TYPE="RESET"VALUE=Clear>'; print '</FORM>', end_html;
    But when I do that I don't get anything. Also how do I pass the @params to an sql statement Would it be something like my $sth = $dbh->prepare("SELECT * FROM $table WHERE tissue = @fields to search;"); THanks for any possibble answers in advance