connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_string($conn, $_GET["device"]) . "' AND DATE(ts)='".date("Y-m-d")."' 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 ' #style 1a1ac94e #ffff00 0.4980392156862745 4 #00ff00 0.4980392156862745 '; while($row = $result->fetch_assoc()) { echo $row["lon"] . "," . $row["lat"] . "\n"; } echo ' '; } else { die("No records found."); } $conn->close(); ?>