connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_string($conn, $_GET["device"]) . "' ORDER BY ts ASC;"; $result = $conn->query($sql); if ($result->num_rows > 0) { header('Content-Type: application/vnd.google-earth.kml+xml'); header('Content-Disposition: attachment; filename="export.kml"'); echo ' #yellowPoly 1 1 absolute '; while($row = $result->fetch_assoc()) { echo $row["lon"] . "," . $row["lat"] . "\n"; } echo ' '; } else { die("No records found."); } $conn->close(); ?>