gps_ajax.php 1009 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. ini_set("display_errors", "1");
  3. error_reporting(E_ALL);
  4. require("connection.php");
  5. // Opens a connection to a MySQL server
  6. $connection=mysql_connect ($dbhost, $dbuser, $dbpass);
  7. if (!$connection) {
  8. die('Not connected : ' . mysql_error());
  9. }
  10. // Set the active MySQL database
  11. $db_selected = mysql_select_db($db, $connection);
  12. if (!$db_selected) {
  13. die ('Can\'t use db : ' . mysql_error());
  14. }
  15. // Select all the rows in the markers table
  16. $query = "SELECT * FROM markers WHERE 1 ORDER BY timestamp";
  17. $result = mysql_query($query);
  18. if (!$result) {
  19. die('Invalid query: ' . mysql_error());
  20. }
  21. // Iterate through the rows, adding XML nodes for each
  22. while ($row = @mysql_fetch_assoc($result)){
  23. $row['lat'] = doubleval($row['lat']);
  24. $row['lng'] = doubleval($row['lng']);
  25. $row['alt'] = floatval($row['alt']);
  26. $row['hdop'] = intval($row['hdop']);
  27. $row['timestamp'] = strtotime($row['timestamp']);
  28. $row['format'] = date('d.m.Y H:i:s', $row['timestamp']);
  29. $json[] = $row;
  30. }
  31. echo json_encode($json);
  32. ?>