
<?php

// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('μαθημα', 'μεσος όρος'));

// fetch the data
include "dbconnect.php";
// loop over the rows, outputting them



 
$q =  mysqli_query($con,"SELECT lesson, AVG(grade) FROM pan2014 GROUP BY lesson"); 
 
while($row = mysqli_fetch_array($q))fputcsv($output, $row);

?>