Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:56:37+00:00 2026-06-06T22:56:37+00:00

Given a MySQL table of real estate data, I would like to generate a

  • 0

Given a MySQL table of real estate data, I would like to generate a KML file with the following output:

<?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Placemark>
      <name>Property Address Pulled from Address Field</name>
      <description>
      Some descriptive data pulled from table inserted here.
      </description>
      <Point>
        <coordinates>Latitude FROM Lat,Long FROM Lng</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

This is the code I have so far. As you can see, I am having trouble writting a loop that will structure my KML as shown above. Any help is highly appreciated!

<?php 
require("phpsqlgeocode_dbinfo.php");

// Start XML file, create parent node
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true; //This was added from the PHP Doc. Nice output.

// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://www.opengis.net/kml/2.2', 'kml');
$parNode = $dom->appendChild($node);

// Creates a KML Document element and append it to the KML element.
$dnode = $dom->createElement('Document');
$docNode = $parNode->appendChild($dnode);

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers table
$query = sprintf("SELECT * FROM markers");
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: application/vnd.google-earth.kml+xml");

// Iterate through the rows, adding KML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $dnode = $dom->createElement("Placemark");
  $newnode = $docNode->appendChild($dnode);
  $newnode = $newnode->createElement("Name");
  $newnode = $newnode->createElement("Description");  
  $newnode = $newnode->createElement("Coordinates");
  }
echo $dom->saveXML() . "\n";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:56:38+00:00Added an answer on June 6, 2026 at 10:56 pm

    createElement() is a method of the DOMDocument class (the root document $dom) and not of DOMElement, to my knowledge (and based on my reading of the documentation.

    You have created 3 new elements, but you have not appended any of them as children of $dnode. Use $dom->createElement() for each and append it to the correct $dnode (Placemark)

    // Iterate through the rows, adding KML nodes for each
    while ($row = mysql_fetch_assoc($result)){
        $dnode = $dom->createElement("Placemark");
        $newnode = $docNode->appendChild($dnode);
    
        // Append each $newnode after creating from $dom
        // Set its nodeValue to a column from your fetch call
        // before appending it to the parent node
        // Substitute your correct column names from mysql_fetch_assoc()
        $newnode = $dom->createElement("Name");
        $newnode->nodeValue = $row['Name'];
        $dnode->appendChild($newnode);
    
        $newnode = $dom->createElement("Description");  
        $newnode->nodeValue = $row['Description'];
        $dnode->appendChild($newnode);
    
        //Coordinates are a child node of the 'Point' node       
        $pointnode = $dom->creteElement("Point");
        $dnode-appendChild($pointnode);
    
        $coordsnode = $dom->createElement("Coordinates");
        $coordsnode->nodeValue = $row['Coordinates'];
        $pointnode->appendChild($coordsnode);
    }
    echo $dom->saveXML() . "\n";
    

    To force a .kml filename, use a Content-Disposition header:

    header("Content-type: application/vnd.google-earth.kml+xml");
    header("Content-disposition: inline; filename=$somefilename.kml");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table in MySQL with rows that have a 'Country' field, I need
Given a [mysql] database with a given schema, is it possible to generate an
I have the following mysql table -------------------------------------------------------- |id | hometeam |goalsfor|goalsagainst| awayteam | --------------------------------------------------------
I have a MySQL table comment with the following fields: loginid submissionid points I
I have a MySQL table called Hotel . in that i have the following
I need to find best matches from a mysql table given a set of
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?
I have 10 tables in my database(MySQL). two of them is given below tbl_state
Given a bunch of images .gif which I retrieve from mySQL, I need to
Is it possible in MySQL to select from a static set of integers? Given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.