PHP with MySQL and Google maps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loislane
Forum Newbie
Posts: 2
Joined: Fri Jul 17, 2009 10:30 am

PHP with MySQL and Google maps

Post by loislane »

I'm trying to implement a simple PHP tutorial for Google maps (http://www.map-server.com/googlemaps/tutorial_api2.html), but it isn't working on my Win XP pc using Firefox v 3.0 or IE7. I'm getting this error message:
PHP Warning: mysql_fetch_array(): 4 is not a valid MySQL result resource in C:\Inetpub\wwwroot\dir\index9.php on line 41

Any idea what's going on? Should I be posting this elsewhere?

The code is:
<script type="text/javascript">
//<![CDATA[
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(51.512161, -0.14110), 11, G_NORMAL_MAP);

// 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("localhost", "id", "pass") or die("Could not connect: " . mysql_error());
mysql_selectdb("tblMyTable",$link) or die ("Can\'t use dbmapserver : " . mysql_error());

$result = mysql_query("SELECT * FROM markers",$link);
mysql_free_result($result);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
echo "var point = new GLatLng(" . $row['lat'] . "," . $row['lng'] . ");\n";
echo "var marker = createMarker(point, '" . addslashes($row['name']) . "');\n";
echo "map.addOverlay(marker);\n";
echo "\n";
}

mysql_close($link);
?>
//]]>
</script>
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: PHP with MySQL and Google maps

Post by andyhoneycutt »

I'll take a look at this and help you but would you do me a favor first? Publish the code you are referencing in

Code: Select all

or

Code: Select all

tags so it's easier to tell where the problem is.

That said, why are you trying to free the result resource before you even use it?
Post Reply