#!/user/perl/ use CGI q~:standar~; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI print "Content-type: text/html\n\n"; my ($dbh, $sth, $filename, @votes, $average, $i); $filename = $ENV{'QUERY_STRING'}; $dbh = DBI -> connect ('dbi:ODBC:', '', '') or die $DBI::errstr; $sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from FanRatings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @votes = $sth -> fetchrow_array; $average = ((1 * $votes[0]) + (2 * $votes[1]) + (3 * $votes[2]) + (4 * $votes[3]) + (5 * $votes[4])) / 5; $i = 1; while ($i <= $average) { print qq~Full Star ~; $i++ } if ($average =~ /\d\.\d/) { print qq~Half Full Star~; } while ($i <= 5) { print qq~Empty Star ~; $i++ } $dbh -> disconnect(); #### #!/user/perl/ use CGI q~:standar~; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI print "Content-type: text/html\n\n"; my ($dbh, $sth, $filename, @votes, $average, $i); $filename = $ENV{'QUERY_STRING'}; $dbh = DBI -> connect ('dbi:ODBC:FFmisc', 'Eaglef93', 'garnet0114') or die $DBI::errstr; $sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from FanRatings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @votes = $sth -> fetchrow_array; if (defined $votes[0]) { $average = ((1 * $votes[0]) + (2 * $votes[1]) + (3 * $votes[2]) + (4 * $votes[3]) + (5 * $votes[4])) / 5; $i = 0; while ($i <= $average) { print qq~Full Star ~; $i++ } if ($average =~ /\d\.\d/) { print qq~Half Full Star~; } while ($i <= 5) { print qq~Empty Star ~; $i++ } } else { print qq~Be the first to rate this Fan Creation.~; } $dbh -> disconnect();