-
Notifications
You must be signed in to change notification settings - Fork 0
/
journeyxml.php
54 lines (45 loc) · 1.52 KB
/
journeyxml.php
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
44
45
46
47
48
49
50
51
52
53
54
<?php
require("userid.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
} // Opens a connection to a MySQL server
$connection=mysql_connect ('hoguslg.uib.no:3306', $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}// Select all the rows in the markers table
$query ="
SELECT DISTINCT a_name, lon, lat, info ,journey_index
FROM journey,region reg
WHERE journey_index =1 AND (journey_from=reg.id OR journey_to=reg.id)
GROUP BY a_name";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type:text/xml");
// Starter XML
echo'<journeys>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<journey ';
echo utf8_encode('name="' . parseToXML($row['a_name']) . '" ');
echo utf8_encode('info="' . parseToXML($row['info']) . '" ');
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lon'] . '" ';
echo 'type="' . $row['journey_index'] . '" ';
echo '/>';
}
// End XML file
echo '</journeys>';
?>