Guest User

Untitled

a guest
May 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. require("config.php");
  3.  
  4. function parseToXML($htmlStr) {
  5. $xmlStr=str_replace('<','<',$htmlStr);
  6. $xmlStr=str_replace('>','>',$xmlStr);
  7. $xmlStr=str_replace('"','"',$xmlStr);
  8. $xmlStr=str_replace("'",'&#39;',$xmlStr);
  9. $xmlStr=str_replace("&",'&',$xmlStr);
  10.  
  11. return $xmlStr;
  12. }
  13.  
  14. // Opens a connection to a MySQL server
  15. $connection=mysqli_connect($databaseHost, $databaseUsername, $databasePassword);
  16.  
  17. if (!$connection) {
  18. die('Not connected : ' . mysqli_error())
  19. }
  20.  
  21. // Set the active MySQL database
  22. $db_selected = mysqli_select_db($connection, $databaseName);
  23.  
  24. if (!$db_selected) {
  25. die ('Can't use db : ' . mysqli_error());
  26. }
  27.  
  28. // Select all the rows in the markers table
  29. $query = "SELECT * FROM markers WHERE 1";
  30. $result = mysqli_query($connection, $query);
  31.  
  32. if (!$result)
  33. die('Invalid query: ' . mysqli_error($connection));
  34. }
  35.  
  36. header("Content-type: text/xml");
  37.  
  38. // Start XML file, echo parent node
  39. echo "<?xml version='1.0' encoding='UTF-8'?>";
  40. echo '<markers>';
  41. $ind=0;
  42.  
  43. // Iterate through the rows, printing XML nodes for each
  44. while ($row = @mysqli_fetch_assoc($result))
  45. // Add to XML document node
  46. echo '<marker ';
  47. echo 'id="' . $row['id'] . '" ';
  48. echo 'name="' . parseToXML($row['name']) . '" ';
  49. echo 'address="' . parseToXML($row['address']) . '" ';
  50. echo 'contact_number="' . parseToXML($row['contact_number']) . '" ';
  51. echo 'contact_number1="' . parseToXML($row['contact_number1']) . '" ';
  52. echo 'contact_number2="' . parseToXML($row['contact_number2']) . '" ';
  53. echo 'lat="' . $row['lat'] . '" ';
  54. echo 'lng="' . $row['lng'] . '" ';
  55. echo 'image="' . $row['image'] . '" ';
  56. echo '/>';
  57. $ind = $ind + 1;
  58. }
  59.  
  60. // End XML file
  61. echo '</markers>';
  62.  
  63. ?>
Add Comment
Please, Sign In to add comment