PHP,MySQL, and Google Maps
Posted by: MajorGeek
Posted on: 2005-10-25 17:24:00
I've been playing around with the Google Map API, but when I started playing around with retrieving points to map from a MySQL database, I guess I'm in over my head. For one thing, the Google Maps tutorial, http://www.map-server.com/googlemaps/tutorial.html uses PHP, and I've never done a project in PHP. The tutorial uses mysql_connect, while my PHP text "PHP and MySQL Web Development" uses the improved call mysqli_connect, available with PHP 5. Does DH's PHP 4.3.10 offer the improved calls?
I'm not getting any DB connect errors but I'm also getting no map. (See http://ykfp.org/googlemaps/dbmap1.htm) What are some good tricks in PHP to see if the connection is made and the arrays contain the correct stuff?
My code currently looks like this:
<html>
<head>
<title>Yakama Fisheries Facilities in the Yakima Basin</title>
<script src="http://maps.google.com/maps?file=api&v=1&key=********" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
</style></head>
<body>
<p><strong>Yakama Fisheries Facilities in the Yakima Basin</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
//<![CDATA[
var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(-120.583735, 46.633379), 6);
// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};
<?php
$link = mysql_connect('mysql.ykfp.org', 'selectonly', 'satus2')
or die("Could not connect: " . mysql_error());
mysql_selectdb('db28989a',$link) or die ("Can't use db28989a : " . mysql_error());
$result = mysql_query("SELECT * FROM Export_Output",$link);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
echo "var point = new GPoint(" . $row['long'] . "," . $row['lat'] . ");n";
echo "var marker = createMarker(point, '" . $row['project_na'] . "');n";
echo "map.addOverlay(marker);n";
echo "n";
}
mysql_close($link);
?>
//]]>
</script>
</body>
</html>