heres the problem. i have to out put a table containing the scores for each team for each sport in which it partakes. the output is fine until i try to output the score when a certain department doesn't compete in the sport. i tried to use the if statement beloe to print a "na" if the team didn't compete but when i do this it ignores the sth5 whileloop and just prints "NA" for all the values i tried to use
if ($sth5->rows == 0){ print "<td> NA </td>; }
but again it just prints out the "NA" for each one. The while loop is used cos the my($thisscore) = $sth5->fetchrowarray() kept kikkin up errors.
#!/usr/local/bin/perl -w use DBI; use CGI qw(:standard); print header; print start_html; $ENV {'ORACLE_HOME'}= '/oracle/u01'; $host="neptune"; $sid="ora1"; $username="tayloja1"; $password="the.best"; $sport = 'basketball'; $dbh = DBI->connect( "dbi:Oracle:host=$host;sid=$sid",$username, $pass +word)|| die "Can't connect to Oracle"; $sth = $dbh->prepare("SELECT year from compsize WHERE sport = \'$spor +t\'")|| die "couldn't prepareSQL statement"; $sth->execute || die "can't execute sql statement"; print "<table border=1> \n"; print "<tr> \n"; print "<th> List of info </th> \n"; print "<tr> \n"; my ($thisyear)= $sth->fetchrow_array(); $sth->finish; print "<tr> \n"; print "<td>$thisyear</td> \n"; print "</tr> \n"; my @deplist = ('Business School', 'Admin/Estates', 'CEAC', 'Civ Eng', +'Combined Honours', 'CSAM', 'EEAP', 'Mod Lang', 'Mech Eng', 'Pharmacy +', 'Vision Sciences'); my @sportlist = ('campus relay', 'archery', 'badminton', 'basketball' +, 'cricket', 'football','hockey','netball','rugby', 'snooker', 'squa +sh','swimming', 'table tennis','tennis','tug of war', 'volleyball' ); print "<table border=1> \n"; print "<tr> \n"; print "<th> List of info </th> \n"; print "<tr> \n"; $sth4 = $dbh->prepare("SELECT department from tempres WHERE year = \'$ +thisyear\' ORDER BY besttwelve DESC ")|| die "couldn't prepare SQL s +tatement"; $sth4->execute || die "can't execute sql statement"; my $thisno = 0; my @newdeplist; while (@row2 = $sth4->fetchrow_array()) { $newdeplist[$thisno] = $row2[0]; $thisno++; } print "<FORM ACTION='/http://www.cs.aston.ac.uk/cgi-bin/cgiwrap/tayloj +a1/deleteseason.pl/' METHOD=/'POST/'>\n"; print "<table border=1> \n"; for $newdep(0..$#newdeplist){ print "<tr>\n"; my $position = $newdep + 1; print "<td>$position</td> \n"; print "<td>$newdeplist[$newdep]</td> \n"; for $sport(0..$#sportlist){ $sth5 = $dbh->prepare("SELECT score from results WHERE year = \'$t +hisyear\' AND sport = \'$sportlist[$sport]\' AND department = \'$newd +eplist[$newdep]\'")|| die "couldn't prepare SQL statement"; $sth5->execute || die "can't execute sql statement"; if ($sth5->rows != 0){ my @row4; while (@row4 = $sth5->fetchrow_array()) { $thisscore = $row4[0]; print "<td>$thisscore</td> \n"; } } elsif ($sth5->rows == 0) { print "<td>NA</td> \n"; } } $sth6 = $dbh->prepare("SELECT total,besttwelve from tempres WHERE year + = \'$thisyear\' AND department = \'$newdeplist[$newdep]\' ")|| die +"couldn't prepare SQL statement"; $sth6->execute || die "can't execute sql statement"; my @row3; while (@row3 = $sth6->fetchrow_array()) { $thistotal = $row3[0]; $twelve = $row3[1]; print "<td>$thistotal</td> \n"; print "<td>$twelve</td> \n"; }
got no ideas on this one guys so any help would b great oh and sorry about the formatting cheers.

In reply to small cgi output problem by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.