prepare($sql);
	
	//check if successful
	if (!$statement){
		$message = "prepare fail";
	}
	
	//execute
	if ($statement->execute()){
		$resultsTable="h1>Customer Preferences Average";
		
		if ($statement->rowCount() > 0){
			
			$resultsTable .= "table>";
			$resultsTable .= "Mon/Wed";
			$resultsTable .= "Tues";
			$resultsTable .= "Wed";
			$resultsTable .= "Tues/Thu";
			
			while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
			$resultsTable .= "";
			$resultsTable .= $row['cust_pref1'];		
			$resultsTable .= "";
			$resultsTable .= $row['cust_pref2'];	
			$resultsTable .= "";
			$resultsTable .= $row['cust_pref3'];
			$resultsTable .= "";
			$resultsTable .= $row['cust_pref4'];	
			$resultsTable .= "";	

			$cust_pref1_total += $row['cust_pref1'];
			$cust_pref2_total += $row['cust_pref2'];
			$cust_pref3_total += $row['cust_pref3'];
			$cust_pref4_total += $row['cust_pref4'];			
		
			}
			$mon_wed =round($cust_pref1_total/($statement->rowCount()), 2);
			$tue=round($cust_pref2_total/($statement->rowCount()), 2);
			$wed=round($cust_pref3_total/($statement->rowCount()), 2);
			$tue_thu=round($cust_pref4_total/($statement->rowCount()), 2);	
			
			$resultsTable .= "tr>td>";
			$resultsTable .= $mon_wed;
			$resultsTable .= "/td>td>";			
			$resultsTable .= $tue;
			$resultsTable .= "/td>td>";			
			$resultsTable .= $wed;
			$resultsTable .= "/td>td>";
			$resultsTable .= $tue_thu;			
			$resultsTable .= "/td>/tr>";			
			$resultsTable .= "/table>";
		}
		
	}
	
	
	
	
} catch (PDOException $e){
	$message .= "oops there's another error";
	error_log($e->getMessage());
	
}

	$preference = min ($mon_wed, $tue, $wed, $tue_thu);
	$chosen_day = "";
	
	switch ($preference) {
		case $mon_wed:
		$chosen_day = "Monday/Wednesday 10:10am-Noon";
		break;
		
		case $tue:
		$chosen_day = "Tuesday 6:00-9:00pm";
		break;	
		
		case $wed:
		$chosen_day = "Wednesday 6:00-9:00pm";
		break;	

		case $tue_thu:
		$chosen_day = "Tuesday/Thursday 10:10am-Noon";
		break;		
	}
	

//close statement and connection_aborted
$statement = null;
$conn = null;
?>