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 > Re: CGI and DBI...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 1426 of 1496
Post > Topic >>

Re: CGI and DBI : using db queries in html

by nshephard@[EMAIL PROTECTED] (Neil) Nov 9, 2007 at 01:55 AM

Thanks to all who replied (David Moreno Garza, Paul Lallo, and Sean
Davis who replied off-list).

Sean very kindly pointed out that I was in fact only one row with my
fetchrow_array statement.

Paul is correct and [ @[EMAIL PROTECTED]
 ] and \@[EMAIL PROTECTED]
 are in this instance
synonyms.

My script now works :D and for reference is included below (in case
others are searching for similar solutions).

Thanks for your help,

Neil

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

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

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

## Grab the datasets that are available by querying the
## 'studies' table
##
## TODO : Eventially need to make this so that it is base
##        on the user's permissions
my $statement = 'SELECT study FROM studies';
my $query     = $dbh   -> prepare($statement);
$query -> execute();
print "$query\n";
my @[EMAIL PROTECTED]
 Grab all rows from the query and place in the @[EMAIL PROTECTED]
 array
 while(my $study = $query   -> fetchrow_array){
   push @[EMAIL PROTECTED]
 $study;
 }

## 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 => "dbselect2.pl", -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]
 ], -default => '' -labels => ''),

## End the form
      $q -> endform,
      $q -> hr, "\n",
      $q -> p("<a href=\"\" target=\"\">gDRAW</a> was written by <a
href=\"mailto:nshephard \<at\> gmail.com\">Neil Shephard</a>."), "\n",
      $q -> end_html;

exit;
 




 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 Fri Nov 21 20:34:45 CST 2008.