Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > CGI and DBI : u...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 1426 of 1478
Post > Topic >>

CGI and DBI : using db queries in html

by nshephard@[EMAIL PROTECTED] (Neil) Nov 8, 2007 at 11:22 AM

Hi,

I've a perl script that I'm working on to get a list of options from a
database presented to a user in a form.  I can do the db query fine
and store the variables in an array, but I can't workout how to get
the array printed as a list of items in a menu.

The script is....

#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Apache;
use DBI;

### Initialise a new CGI object
my $q   = new CGI;


## Define the database connectin
my $user = "xxxx";
my $dbh  = DBI ->
connect('DBI:mysql:localhost:database=gdraw;host=localhost;****t=3306',
$user,'xxxxx') || exit;

## Grab the datasets that are available by querying the
## 'studies' table
my $statement = 'SELECT study FROM studies';
my $query     = $dbh   -> prepare($statement);
$query -> execute();
my @[EMAIL PROTECTED]
 = $query   -> fetchrow_array;

## Print the web-page
print $q -> header,
      $q -> start_html(-title => "gDRAW - Genotype Database, R &
Analysis Web-interface", -style => {-src => "/css/gdraw1.css"}), "\n",
      $q -> h1("Existing Data"), "\n",
      $q -> p("You can select cohorts, markers and phenotypes to load
from below"), "\n",

## Start the form
      $q -> start_form(-action => "", -method => "post", -
enctype=>"multipart/form-data"),

## Have a pull-down box for selecting the studies that the
## user can access
      $q -> popup_menu(-name => 'study_select', -values =>
[@[EMAIL PROTECTED]
),

## End the form
      $q -> endform,
      $q -> end_html;

exit;


The section that I'm having trouble with is...

## Have a pull-down box for selecting the studies that the
## user can access
      $q -> popup_menu(-name => 'study_select', -values =>
[@[EMAIL PROTECTED]
),

@[EMAIL PROTECTED]
 is of length 2, but only one of these gets listed in the menu
that is generated.

Can anyone suggest how I go about using an array as a list of values
(and labels) in a popup_menu()?

Thanks for taking the time to look at this problem,

Neil
 




 4 Posts in Topic:
CGI and DBI : using db queries in html
nshephard@[EMAIL PROTECTE  2007-11-08 11:22:50 
Re: CGI and DBI : using db queries in html
damog@[EMAIL PROTECTED]   2007-11-08 18:34:04 
Re: CGI and DBI : using db queries in html
mritty@[EMAIL PROTECTED]   2007-11-08 18:23:11 
Re: CGI and DBI : using db queries in html
nshephard@[EMAIL PROTECTE  2007-11-09 01:55:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 6:21:44 CDT 2008.