Location: PHPKode > projects > Operational Information > opinfo-1.2/download_traffic.php
<?php

// IMPORT SETTINGS
include("settings.php");

// CONNECT DB
$con = mysql_connect($database_hostname, $database_username, $database_password);
mysql_select_db($database_name, $con);

// TABLE NAME
$table = $database_table_prefix . "_op_traffic";

// HEADING
$csv = "DATE,TIME,TYPE,REG,COMMENTS,CREATED DATE,CREATED TIME,DELETED DATE,DELETED TIME\n";

// FIND DATA
$query = "SELECT * FROM $table ORDER BY time";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) 
	{
	$id = $row["id"];
	$cre_date = gmdate("Y-m-d",$row["created_time"]);
	$cre_time = gmdate("H:i:s",$row["created_time"]);
	$date = gmdate("Y-m-d",$row["time"]);
	$time = gmdate("H:i",$row["time"]);
	$type = $row["type"];
	$registration = $row["registration"];
	$comments = $row["comments"];
	$del_date = "";
	$del_time = "";
	if ($row["deleted_time"] != 0)
		{
		$comments = $row["comments"] . " ***DELETED***";
		$del_date = gmdate("Y-m-d",$row["deleted_time"]);
		$del_time = gmdate("H:i:s",$row["deleted_time"]);
		}
	$csv .= $date.",".$time.",".$type.",".$registration.",".$comments.",".$cre_date.",".$cre_time.",".$del_date.",".$del_time."\n";
	}
	

//header("Content-type: application/vnd.ms-excel"); // makes xls endingto the end
//header("Content-type: text/csv"); // work fine, er anbefalt i en artikkel
//header("Content-type: text/comma-separated-values");//anbefalt i en artikkel som best
header("Content-type: application/octet-stream");//ble slik etter csv fil uploaded til gmail. blir ogsa foreslatt pa andre artikler
header("Content-disposition: csv; filename=" . gmdate("Y-m-d_H:i:s") . "_".$table.".csv; size=".strlen($csv));
echo "*** TRAFFIC REPORT ***
AERODROME NAME: " . strtoupper($aerodrome_name) . "
AERODROME ICAO CODE: " . strtoupper($aerodrome_icao_code) . "
REPORT TIME: " . gmdate("Y-m-d H:i:s",time()) . " UTC
TIP: SAVE FILE AND IMPORT INTO I.E. EXCEL OR CALC AS COMMA SEPARATED VALUES
-------------------------------------------------------------------------------
" . $csv;
exit;
?>
Return current item: Operational Information