#!/usr/bin/perl
#Display Odour information
use CGI;
use DBI;
print "Content-type: text/html\n\n";
$a = <<"ENDA";
Odour keywords
ENDA
print $a;
$query = new CGI;
$odour = $query->param('odour');
print "Search for $odour
";
# Open the database
$hostname = "localhost:3306";
$database = "rmottram_odour";
$user="rmottram_odour";
$password="kja3vcu!eqk4WZF0epa";
$|=1; # Don't buffer output
$statement = "Select DISTINCT Compound_ID from Odour_Data where Odour='$odour'";
$dbh = DBI->connect("DBI:mysql:$database:$hostname", $user, $password) or die "Couldn't connect to database: " . DBI->errstr;
$sth = $dbh->prepare($statement) or die print "can't prepare the statement";
$rv = $sth->execute or die print "can't execute the query: $sth->errstr";
#Display the Records
while(@row = $sth->fetchrow_array) {
$statement_compound = "SELECT Compound from Compound_Data WHERE Compound_ID='@row'";
$sth_compound = $dbh->prepare($statement_compound) or die print "can't prepare the statement";
$rv = $sth_compound->execute or die print "can't execute the query: $sth->errstr";
@compound_name = $sth_compound->fetchrow_array;
print "view @compound_name ";
$statement2 = "SELECT DISTINCT Odour from Odour_Data WHERE Compound_ID='@row'";
$sth2 = $dbh->prepare($statement2) or die print "can't prepare the statement";
$rv = $sth2->execute or die print "can't execute the query: $sth->errstr";
while(@odour = $sth2->fetchrow_array) {
print "@odour, ";
}
print "";
}
$a = <<"ENDB";
ENDB
print $a;
$rc = $sth->finish;
#$rc = $sth2->finish;
#$rc = $sth_compound->finish;
$rc = $dbh->disconnect;