#!/user/perl/ use CGI q~:standard~; 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, TotalVotes from FanRatings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @votes = $sth -> fetchrow_array; if (defined $votes[0]) { #$average = (($votes[0] + $votes[1] + $votes[2] + $votes[3] + $votes[4]) / $votes[5]); $average = 3; $i = 0; while ($i > 0 and $i <= $average) { print qq~Full Star ~; $i++ } if ($average =~ /\d\.\d/) { print qq~Half Full Star~; $i = $i + 0.5 } while ($i <= 4) { print qq~Empty Star ~; $i++ } } else { $i = 0; while ($i <= 4) { print qq~Empty Star ~; $i++ } print qq~
Be the first to rate this Fan Creation.~; } $dbh -> disconnect();