BUGFIX: for loop over a possible undefined variable
authorArun Persaud <arun@nubati.net>
Wed, 4 Feb 2009 03:28:36 +0000 (19:28 -0800)
committerArun Persaud <arun@nubati.net>
Wed, 4 Feb 2009 03:28:36 +0000 (19:28 -0800)
for the first game in a session there is no score to display yet, need
to check if the score variable is empty or not before I loop over it.

include/game.php

index 377d0aa017dba09776f81d21718274fc7c1f8769..845a5629b6cea269fab793e38ef4bff6b3b1af8d 100644 (file)
@@ -215,12 +215,23 @@ if($session)
     $finalscore = array_pop($tmpscore);
     $finalscore = $finalscore['players'];
 
     $finalscore = array_pop($tmpscore);
     $finalscore = $finalscore['players'];
 
-    echo "  <div class=\"sessionscore\">Score: \n";
-    foreach($finalscore as $user=>$value)
+    echo "  <div class=\"sessionscore\">";
+    if($finalscore)
+      { 
+       echo "Score: \n";
+       /* output the final score on the front page */
+       foreach($finalscore as $user=>$value)
+         {
+           $name = DB_get_name('userid',$user);
+           echo " ".substr($name,0,2).": $value ";
+         }
+      }
+    else 
       {
       {
-       $name = DB_get_name('userid',$user);
-       echo " ".substr($name,0,2).": $value ";
+       /* first game, no score yet */ 
+       echo "&nbsp;";
       }
       }
+
     echo format_score_table_html($score,$myid);
     echo "  </div>\n";
 
     echo format_score_table_html($score,$myid);
     echo "  </div>\n";