Browse Source

[svn r17659] Minor - Logic Changes - Fixed warning: Division by zero in /var/www/dokeossvn/main/mySpace/index.php on line 1050 see FS#2608

Cristian Fasanando 16 years ago
parent
commit
456f65d68f
1 changed files with 7 additions and 1 deletions
  1. 7 1
      main/mySpace/index.php

+ 7 - 1
main/mySpace/index.php

@@ -1030,11 +1030,15 @@ function course_info_tracking_filter($user_id,$url_params,$row)
  */
 function exercises_results($user_id, $course_code)
 {
+	$questions_answered = 0;
 	$sql = 'SELECT exe_result , exe_weighting
 					FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)."
 					WHERE exe_cours_id = '".Database::escape_string($course_code)."'
 					AND exe_user_id = '".Database::escape_string($user_id)."'";
 	$result = api_sql_query($sql, __FILE__, __LINE__);
+	$score_obtained = 0;
+	$score_possible = 0;
+	$questions_answered = 0;
 	while ($row = Database::fetch_array($result))
 	{
 		$score_obtained += $row['exe_result'];
@@ -1042,7 +1046,9 @@ function exercises_results($user_id, $course_code)
 		$questions_answered ++;
 	}
 	
-	$percentage = round(($score_obtained / $score_possible * 100),2);
+	if ($score_possible !== 0) {
+		$percentage = round(($score_obtained / $score_possible * 100),2);	
+	} 
 	
 	return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage);
 }