summaryrefslogtreecommitdiff
path: root/tableKML.php
blob: 1007f427ed4b72b8d63d036d3f9c0238de31d926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php //ini_set('display_errors','1');ini_set('display_startup_errors','1');error_reporting(E_ALL|E_STRICT); ?>
<?php

header("Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8");
//header("Content-Type: text/html; charset=utf-8");

include 'config.php';

mysql_connect($host, $login, $pword) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

$table= $_GET['table'];

$query='SELECT * FROM '.$table;
$result = mysql_query($query);

#http://stackoverflow.com/questions/1567758/best-way-to-use-jquerys-ajax-function-retrieve-variables-from-a-php-script

$output = '';
$output .= "<?xml version='1.0' encoding='UTF-8'?>\n";
$output .= "<kml xmlns='http://www.opengis.net/kml/2.2'>\n";

$n=mysql_numrows($result);
$i=0;

while ($i < $n) {
	$T=mysql_fetch_array($result, MYSQL_ASSOC);
	$output .= "<Placemark>\n";
	$output .= "<name>".str_replace('&', '&amp;', $T['name'])."</name>\n";
	$output .= "<Point>\n";
        $output .= "<coordinates>".$T['lat'].",".$T['lng'].",0</coordinates>\n";
	$output .= "</Point>\n";
	$output .= "</Placemark>\n";
	$i +=1;

}
mysql_close();

$output .= "</kml>\n";

echo $output;

?>