Advertisement
pushpesh4u

marker php with db

Jul 5th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php  
  2. // Opens a connection to a MySQL server
  3.  
  4. $connection=mysql_connect ('localhost', 'root', '');
  5. if (!$connection) {  die('Not connected : ' . mysql_error());}
  6.  
  7. // Set the active MySQL database
  8. $db_selected = mysql_select_db('test', $connection);
  9. if (!$db_selected) {
  10. die ('Can\'t use db : ' . mysql_error());
  11. }
  12.  
  13. // Start XML file, create parent node
  14.  
  15. $dom = new DOMDocument("1.0");
  16. $node = $dom->createElement("markers");
  17. $parnode = $dom->appendChild($node);
  18.  
  19. // Select all the rows in the markers table
  20.  
  21. $query = "SELECT * FROM markers WHERE 1";
  22. $result = mysql_query($query);
  23. if (!$result) {  
  24. die('Invalid query: ' . mysql_error());
  25. }
  26.  
  27. header("Content-type: text/xml");
  28.  
  29. // Iterate through the rows, adding XML nodes for each
  30.  
  31. while ($row = @mysql_fetch_assoc($result)){  
  32. // ADD TO XML DOCUMENT NODE  
  33. $node = $dom->createElement("marker");  
  34. $newnode = $parnode->appendChild($node);  
  35. $newnode->setAttribute("name",$row['name']);
  36. $newnode->setAttribute("address", $row['address']);  
  37. $newnode->setAttribute("lat", $row['lat']);  
  38. $newnode->setAttribute("lng", $row['lng']);  
  39. $newnode->setAttribute("type", $row['type']);
  40. }
  41. echo $dom->saveXML();
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement