Consider this corrected code:
$sql = mysql_query("SELECT * FROM `_tkts` WHERE `game_id`='{$row['game_id']}' AND `status`='open'")
OR die(mysql_error()); //for debugging
//check that query returns at least 1 row
if (mysql_num_rows($sql) > 0) {
echo "<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">";
$opentkts = 0;
//loop through result set
while($row = mysql_fetch_array($sql)) {
//print result for current row
echo "<tr bgcolor=\"#CCCCCC\"><td>vs. {$row['agianst']} -- {$row['month']}/{$row['day']}/{$row['year']}</td></tr>";
$opentkts++;
$grandtotal++;
}
echo "<tr><td>TOTAL OPEN TKTS: {$opentkts}</td></tr>";
echo "<tr bgcolor=\"#CCCCCC\"><td>GRAND TOTAL: {$grandtotal}</td></tr></table>";
}
The mistake is obvious.
You are only printing out that output once.
Your loop only increments the $opentkts and $grandtotal variables, aside from populating $row
What you want to do is this:
while end of $sql result set not reached
place current row of $sql result set into $row
increment $sql result pointer
output elements from $row in given format
increment $opentkts
increment $grandtotal
endwhile
What you are doing is this:
output elements from $row in given format
while end of $sql result set not reached
place current row of $sql result set into $row
increment $sql result pointer
increment $opentkts
increment $grandtotal
endwhile
This pseudocode:
while end of $sql result set not reached
place current row of $sql result set into $row
increment $sql result pointer
is implemented as:
while ($row = mysql_fetch_array($sql))