<?php
include_once("config/config.inc.php"); 

$new_name="contactos_" . date("Y-m-d").".csv";
//header("Content-type: application/x-download");
//header("Content-Disposition: attachment; filename={$new_name}");
//header("Content-Transfer-Encoding: binary");

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename={$new_name}");


$csv_output = "id; nome; email; actividade; idCat; activo"; 
$csv_output .= "\n";
    
$sql = "select * from contacto order by nome";

$dblink = mysql_connect($host , $user , $pass );
mysql_select_db($database, $dblink );

$result = mysql_query($sql, $dblink); 

while($row = mysql_fetch_array($result)) { 
   $csv_output .= $row['id'] .";" .
   		$row['nome'].";" .
		$row['email'].";" .
		$row['actividade'].";" .
		$row['idCat'].";" .
		$row['activo']."\n";
} 

print $csv_output;
exit;
?>
