PHP - [DUDA]mysql xml maps

 
Vista:

[DUDA]mysql xml maps

Publicado por robeer (1 intervención) el 28/11/2017 16:24:17
Hola a todos, mi nombre es roberto y recien estoy comenzando en el mundo php que siempre me ha gustado y tengo un problema al generar el xml de mi mini proyecto para trazar trayectorias en google maps, el codigo es el siguiente
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
  include "phpGPS.php";
  $db = new phpGPS_DB();
  $con = $db->connectToDB();
 
  include "login.php";
  $userGroups = "all";
 
  $loginT = null;
  if (isset($con)) {
    $loginT = new login($con, $userGroups);
  }
 
  function parseToXML($htmlStr) {
    $xmlStr=str_replace('<','&lt;',$htmlStr);
    $xmlStr=str_replace('>','&gt;',$xmlStr);
    $xmlStr=str_replace('"','&quot;',$xmlStr);
    $xmlStr=str_replace("'",'&#39;',$xmlStr);
    $xmlStr=str_replace("&",'&amp;',$xmlStr);
    return $xmlStr;
  }
 
  function generateMarkers($con, $marker_id, $showPathMarkers, $markerDelay) {
    // Select all the rows in the markers table
    $markerSql = "";
    if ($marker_id != "") $markerSql = "ge.gps_entry_id = " . phpGPS_DB::cleanInput($marker_id);
 
    //build query, if marker is set, then show regardless of status
    $query = "SELECT \n" .
             "  * \n" .
             "FROM \n" .
             "  gps_entries ge \n" .
			 "WHERE gps_device_id='2'".
             "  left join gps_type gt on ge.gps_type_id = gt.gps_type_id \n";
 
    $query = $query .
             "WHERE \n";
    if ($markerSql == "") {
      $query = $query .
             "  ((ge.gps_status <> 'H' ";
      if (!$showPathMarkers) $query = $query . "AND ge.gps_status <> 'P' ";
      $query = $query . ") or ge.gps_status IS NULL) \n"; //H is Hidden, P is Path Only
    } else {
      $query = $query .
             "  $markerSql \n";
    }
    if ($markerDelay != null && $markerDelay > 0) {
      $query = $query .
             " AND ge.gps_entry_date < NOW() - INTERVAL $markerDelay DAY \n";
    }
 
    $query = $query .
             "ORDER BY \n" .
             "  ge.gps_date;";
    $result = mysqli_query($con, $query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
 
    //Exit if no results
    if ($result->num_rows == 0) return;
 
    //Start Marker XML
    echo '<markers>';
 
    // Iterate through the rows, printing XML nodes for each
    while ($row = @mysqli_fetch_assoc($result)){
      echo '<marker ';
      echo 'id="' . parseToXML($row['gps_entry_id']) . '" ';
      echo 'name="' . parseToXML($row['gps_name']) . '" ';
      echo 'comment="' . parseToXML($row['gps_comment']) . '" ';
      echo 'address="' . parseToXML($row['gps_address1']) . '" ';
      echo 'lat="' . $row['gps_latitude'] . '" ';
      echo 'lng="' . $row['gps_longitude'] . '" ';
      echo 'accuracy="' . $row['gps_accuracy'] . '" ';
      echo 'path_id="' . $row['gps_path_id'] . '" ';
      echo 'type_name="' . $row['gps_type_name'] . '" ';
      echo 'image="' . $row['gps_type_image'] . '" ';
      echo 'custom_icon_name="' . $row['gps_type_icon'] . '" ';
      echo '/>';
    }
 
    // End XML file
    echo '</markers>';
  }
 
  function generatePaths($con, $markerDelay) {
    $query = "SELECT \n" .
             "  *\n" .
             "FROM \n" .
             "  gps_path gp\n" .
             "WHERE \n" .
             "  (gp.gps_path_status <> 'H' OR gp.gps_path_status IS NULL) \n" .
             "ORDER BY \n" .
             "  gp.gps_path_id;";
 
    $pathResults = mysqli_query($con, $query);
    if (!$pathResults) {
      die('Invalid query: ' . mysql_error());
    }
    if ($pathResults->num_rows == 0) return;
 
    echo '<paths>';
 
    while ($path = @mysqli_fetch_assoc($pathResults)){
      $query = "SELECT \n" .
               "  * \n" .
               "FROM \n" .
               "  gps_entries ge \n" .
               "WHERE \n" .
               "  (ge.gps_status <> 'H' OR ge.gps_status IS NULL) \n" .
               "  AND ge.gps_path_id = " . $path['gps_path_id'] . "\n";
      if ($markerDelay != null && $markerDelay > 0) {
      $query = $query .
               "  AND ge.gps_entry_date < NOW() - INTERVAL $markerDelay DAY \n";
      }
      $query = $query .
               "ORDER BY \n" .
               "  ge.gps_date;";
      $result = mysqli_query($con, $query);
      if ($result->num_rows == 0) break;
 
      echo '<path ';
      echo 'id="'      . $path['gps_path_id']     . '" ';
      echo 'name="'    . $path['gps_path_name']   . '" ';
      echo 'desc="'    . $path['gps_path_desc']   . '" ';
      echo 'type_id="' . $path['gps_type_id']     . '" ';
      echo 'status="'  . $path['gps_path_status'] . '" ';
      echo 'color="'   . $path['gps_path_color']  . '" ';
      echo '>';
 
      // Iterate through the rows, printing XML nodes for each
      while ($row = @mysqli_fetch_assoc($result)){
        echo '<coord ';
        echo 'lat="' . $row['gps_latitude'] . '" ';
        echo 'lng="' . $row['gps_longitude'] . '" ';
        echo '/>';
      }
      echo "</path>";
    }
 
    // End XML file
    echo '</paths>';
  }
 
  $showPathMarkers = false;
  if (isset($_GET['showPathMarkers']) && $_GET['showPathMarkers'] == "true") $showPathMarkers = true;
 
  $markerDelay = 0;
  if ($loginT == null || $loginT->getStatus() == false) {
    $markerDelay = phpGPS_Settings::$_markerDelay;
  }
 
  header("Content-type: text/xml");
  echo "<mapInfo>\n";
  if (isset($_GET['marker_id']) && $_GET['marker_id'] != "") {
    generateMarkers($con, $_GET['marker_id'], $markerDelay);
  } else {
    generateMarkers($con, '', $showPathMarkers, $markerDelay);
    generatePaths($con, $markerDelay);
  }
  echo "</mapInfo>\n";
?>
y yo quiero filtrar lo siguiente que solo me convierta el xml donde las filas de gps device id sean iguales a 2 intente con ese codigo pero no resulto
"WHERE gps_device_id='2'";
desde ya saludos y muchas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder