Guest User

Untitled

a guest
Jun 7th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. $username = "root";
  3. $password = "";
  4. $database = "wordpress";
  5.  
  6. $connection = mysqli_connect('localhost', $username, $password);
  7. if(!$connection) {
  8. while(!$connection){
  9. $connection = mysql_connect('localhost', $username, $password);
  10. }
  11. }
  12.  
  13. $db_selected = mysqli_select_db($connection, $database);
  14. if(!$db_selected){
  15. while(!$db_selected){
  16. $db_selected = mysql_select_db($database, $connection);
  17. }
  18. }
  19.  
  20. $query = "SELECT markers.lng, markers.lat, locations.name AS location_name,
  21. locations.address, locations.type, locations.phone, locations.email,
  22. locations.`work-hours`, locations.description, cities.name AS city_name,
  23. countries.name AS country_name, countries.continent
  24. FROM markers JOIN locations
  25. ON markers.location_id = locations.id
  26. JOIN cities ON locations.city_id = cities.id
  27. JOIN countries ON cities.country_id = countries.id";
  28. $result = mysqli_query($connection, $query);
  29. if(!$result){
  30. while(!$result){
  31. $result = mysql_query($query);
  32. }
  33. }
  34.  
  35. $dom = new DOMDocument("1.0");
  36. $node = $dom->createElement("markers");
  37. $parnode = $dom->appendChild($node);
  38.  
  39. header("Content-type: text/xml");
  40.  
  41. while ($row = @mysqli_fetch_assoc($result)){
  42. $node = $dom->createElement("marker");
  43. $newnode = $parnode->appendChild($node);
  44. $newnode->setAttribute("lat", $row['lat']);
  45. $newnode->setAttribute("lng", $row['lng']);
  46. $newnode->setAttribute("location_name", $row['location_name']);
  47. $newnode->setAttribute("address", $row['address']);
  48. $newnode->setAttribute("type", $row['type']);
  49. $newnode->setAttribute("phone", $row['phone']);
  50. $newnode->setAttribute("email", $row['email']);
  51. $newnode->setAttribute("work-hours", $row['work-hours']);
  52. $newnode->setAttribute("description", $row['description']);
  53. $newnode->setAttribute("city_name", $row['city_name']);
  54. $newnode->setAttribute("country_name", $row['country_name']);
  55. $newnode->setAttribute("continent", $row['continent']);
  56. }
  57.  
  58. echo $dom->saveXML();
  59. ?>
Add Comment
Please, Sign In to add comment