in reply to Re: while loops with two tests not working.
in thread while loops with two tests not working.
I will look into switching to a for loop but for my feature info can a while loop handle two tests?#!/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, TotalVo +tes 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] + $vot +es[4]) / $votes[5]); $average = 3; $i = 0; while ($i > 0 and $i <= $average) { print qq~<img src="http://www.ffinfo.com/images/misc/starfull. +gif" width="15" height="15" alt="Full Star" style="vertical-align: bo +ttom" /> ~; $i++ } if ($average =~ /\d\.\d/) { print qq~<img src="http://www.ffinfo.com/images/misc/starhalf. +gif" width="15" height="15" alt="Half Full Star" style="vertical-alig +n: bottom" />~; $i = $i + 0.5 } while ($i <= 4) { print qq~<img src="http://www.ffinfo.com/images/misc/starempty +.gif" width="15" height"15" alt="Empty Star" style="vertical-align: b +ottom" /> ~; $i++ } } else { $i = 0; while ($i <= 4) { print qq~<img src="http://www.ffinfo.com/images/misc/starempty +.gif" width="15" height"15" alt="Empty Star" style="vertical-align: b +ottom" /> ~; $i++ } print qq~<br />Be the first to rate this Fan Creation.~; } $dbh -> disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: while loops with two tests not working.
by toolic (Bishop) on Jul 20, 2007 at 00:40 UTC | |
by Eagle_f90 (Acolyte) on Jul 20, 2007 at 00:52 UTC | |
|
Re^3: while loops with two tests not working.
by nedals (Deacon) on Jul 20, 2007 at 00:52 UTC | |
|
Re^3: while loops with two tests not working.
by GrandFather (Saint) on Jul 20, 2007 at 00:56 UTC |