#!/usr/bin/perl # Michael Tartaglia # Working with a simple PSQL DBase use Pg; use CGI ':standard'; require template; template::startHTML("Assignment 12","Working With A Database"); my ($sort, $what, $item) = (param("sort"),param("what"),param("query")); my $i = 0; $item =~ s/^(\w*|\d*)\s*(\w*|\d*)/$1$2/; # ELIMINATE SPACES if ($ENV{'QUERY_STRING'} eq "") { # SHOW INSTRUCTIONS IF NO QUERY IS ENTERED print <Look in the Formula 1 Racing database!
This is for the 2002 season to date.

Enter a team name (like Ferrari or Jaguar), a driver's name (like Barrichello or Button), a driver's number, or the three-letter abbreviation for a country. Try a points range by typing the minimum points value you desire (typing 0 will show all drivers, typing 10 will only show those who have 10 points or more). Also choose display order. (If you have no idea what Formula One is, check out Daily F1 for an idea - no, I did not create that site.)

Sorry, but as of May 27, 2002, this database has been disabled. Please refer to my AOL page if you truly want to see the FIA World Championship standings for the 2002 season. Click here to see.

Enter query:

Search in what?


Sort by what?


ENDOFHTML } elsif ($what eq "" || $item eq "") { # ELSE WARN IF BAD QUERY WAS MADE print "You've entered some bad data.
", "Hit the back button or click here", "
"; } elsif (defined($what) && defined($item)) { # ELSE ASSEMBLE SQL QUERY my $condition = "select * from tartagli "; if ($what eq "points") { $condition .= "where points >= " . int($item); } elsif ($what eq "number") { $condition .= "where number = " . int($item); } else { $item = "\U$item\E" if ($what eq "country"); $condition .= "where $what like '%$item%'"; } $condition .= " order by $sort" if ($sort ne ""); my $database = Pg::connectdb("dbname=products"); # CONNECT TO DBASE my $connection = $database->exec("$condition;"); my (@row, @data); $data[$i] = "$row[0]$row[1]" . "$row[2]$row[3]" . "$row[4]\n" and ++$i while (@row = $connection->fetchrow); print "\n", "", "", "\n@data
Car #NameNat.TeamPoints
\n
" if ($i > 0); print "
Your $what query of \"$item\" returned ", "$i results."; print "
Note that query is case sensitive!
" if ($i == 0 && $what ne "country"); } template::endHTML();