connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT ts, lat, lon FROM tracker 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(); ?>