Jump to content

Recommended Posts

Posted

Hi! Trying to learn how to make a MySQL DB to display a set of Google plamemarks on a map.

 

Below is the code I pulled from the web and I'm not sure what the connection info should be - johnny.heliohost.org or

tektours.heliohost etc. Can you help me out? Thanks in advance.

Posted

It doesn't look like your code got attached. Our system doesn't accept binary attachments if that's what you tried. Perhaps just copy/paste the code directly into the email?

Posted (edited)

Interesting as it definately was in the email. I wonder if it stripped out the PHP code because it thought it was email-meta data or something. Anyway, I pulled it from the web so it has come comments in it the original author wrote as well. here it is:

<?php

// Define the database info
// -- Modify for your case --
define("DB_SERVER", "tektours.heliohost.org/localhost/");
define("DB_USER", "XXXXXXXX");
define("DB_PASS", "XXXXXXX");
define("DB_NAME", "XXXXXXX");
define("DB_TABLE", "XXXXXXX");

// Important so that the filetype is correct
header("Content-type: application/xml");

// Print the head of the document
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://earth.google.com/kml/2.0\">
<Document>");

// You can include a default map view using the following lines
// -- Delete this block if you don't need it --
printf("<LookAt>
<latitude>42.390185</latitude>
<longitude>-72.528412</longitude>
<range>1200</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>");

if ($db = mysqli_connect(DB_SERVER, DB_USER, DB_PASS)) {

mysqli_select_db($db, DB_NAME);

$query = "SELECT id, name, web_display, latitute, longtitude FROM " . DB_TABLE;

// You could add some WHERE statements here to filter the data

// DESC means newest first
$query .= " ORDER BY id DESC";

// Finally query the database data
$result = mysqli_query($db, $query);

// Now iterate over all placemarks (rows)
while ($row = mysqli_fetch_object($result)) {

// This writes out a placemark with some data
// -- Modify for your case --
printf('
<Placemark id="%d">
<name>%s says:</name>
<description>%s</description>
<Point>
<coordinates>%f,%f</coordinates>
</Point>
</Placemark>',
htmlspecialchars($row->id),
htmlspecialchars($row->name),
htmlspecialchars($row->web_display),
htmlspecialchars($row->longitude),
htmlspecialchars($row->latitude)
);

};

// Close the database connection
mysqli_close($db);

};

// And finish the document
printf("
</Document>
</kml>");

?>



This is the error message I get:
<kml><Document><br/><b>Warning</b>: mysqli_fetch_object() expects parameter 1 to be mysqli_result, boolean given in <b>/home/pschmidt/public_html/ski_areas.php</b> on line <b>47</b><br/></Document></kml>

I do a SQL all day but am brand new to php.

Edited by tallpaul
removed password
Posted

Well was reading through my script and saw that i had misspelled latitude and it now seems to retrieve the data, but doesn't display on Google Maps though. Progress! Thanks for the heads up on the server name for sure though. .

Guest
This topic is now closed to further replies.
×
×
  • Create New...