HTML Coding Forum

Having trouble with your own webpage HTML coding? Before you post here, use the Search option on the right to search for the answer to your problem. Most problems have been answered previously.

Please do not post advertisements in this forum.



Return to Website

  First
  Prev
  Reply
  Home
Next  
Last  
Search this Forum:  
Viewing Page 1 of 1 (Total Posts: 1)


Author Comment    
ultron2099

ultron2099@yahoo.com alternativewindowsolutions.net/locate/phpsqlsearch_map.html


Apr 30, 08 - 10:10 AM
XML file creation from sql using php

Trying to create an xml file by accessing a sql database and sorting through its files. The overall purpose of this program is to parse out the data and determine which of 54 sites is closest to an entered zip code. Comes in three parts, the main page interface, the search php page, and finally the access codes and database location. I'm including the search php code because I believe there is an error there.

===================PHP CODE======================

require("phpsqldbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection=mysql_connect ($server, $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 name, address, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);

$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}

echo $dom->saveXML();
?>


  First
  Prev
  Reply
  Home
Next  
Last  


powered by Powered by Bravenet bravenet.com