$value){ if(!empty($value)){ $sum = $sum + $value; $n = $n + 1; } } $average = "Error. There were not enough cases to compute an average."; if($n > 0){ $average = $sum/$n; $average = round($average,2); } return $average; } // Show PHP errors in browser ini_set('display_errors',1); // If the user is logged in, he or she will have a cookie on his or her machine. // If no cookie exists, redirect the user to login page. if(!isset($_COOKIE['user_id']) OR !isset($_COOKIE['sessionID']) OR !isset($_COOKIE['first_name']) ){ redirect_user(); exit(); } $user_id = $_COOKIE['user_id']; $tempID = $_COOKIE['sessionID']; $first_name = $_COOKIE['first_name']; // If cookie exists, continue // Include external style sheet print "
"; print "";
print "Welcome, $first_name! "; print "Here is an overview and summary of your scores. "; print " |
";
while($row = mysqli_fetch_array($r, MYSQLI_BOTH) ) {
print "On $row[2] : "; print "Your avoidance score was $row[0] "; print "Your anxiety score was $row[1] "; } // Select ALL avoidance, anxiety scores, regardless of who submitted them. $q2 = "SELECT avoidance,anxiety FROM survey3"; $r2 = @mysqli_query ($dbc, $q2); // Run the query. // Initialize some arrays to hold sample scores $sample_avoidance = array(); $sample_anxiety = array(); // Add each composite score to the array as we loop through the data while($row = mysqli_fetch_array($r2, MYSQLI_BOTH) ) { $sample_avoidance[] = $row[0]; $sample_anxiety[] = $row[1]; } // Compute sample means $sample_mean_avoidance = average_scores($sample_avoidance); $sample_mean_anxiety = average_scores($sample_anxiety); print " "; print "The sample mean for avoidance is $sample_mean_avoidance. "; print "The sample mean for anxiety is $sample_mean_anxiety. "; print " |