i have a database where each row has lat/long info for goggle maps.
each row subsequently gets turned into a marker. when i click on that marker, an info window pops up.
i want the info window to have a button so that when clicked, the entry from the database will get deleted. but my button won’t work. specifically, something about the eraseEntry() function attached to the onClick event isn’t working. when i click the button, only the last entry of the database gets deleted, regardless of which marker i click.
var map=//make the google map
var markersArray = [];
var infoWindow = new google.maps.InfoWindow({content: ""});
var markers;
$.get("phpsqlajax_genxml.php", function(data)
{
markers = data.documentElement.getElementsByTagName("marker");
makeMarkersWithXMLinfo();
});
function makeMarkersWithXMLinfo()
{
for (var i = 0; i < markers.length; i++)
{
var name = markers[i].getAttribute("name");
var markerLocation = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" +
"</b> <br/>" + "</b> <br/>" +
"<input type='button' value='Erase Entry' onclick='eraseEntry()'/>";
var markerWithLocation = new google.maps.Marker({position: markerLocation, map: map});
var markerWithInfo = createMarker(markerWithLocation,html);
eraseEntry = function ()
{
$.get("delete.php", { identifierVar: name } );
}
}
}
function createMarker(markerWithLocation, html) {
var markerWithInfo = google.maps.event.addListener(markerWithLocation, 'click', function(){infoWindow.setContent(html); infoWindow.open(map,markerWithLocation)});
return markerWithInfo;
}
i’m able to pull from the database and create the markers just fine.
i’ve tried having the eraseEntry() function call another function that’s outside of the makeMarkersWithXMLinf() function, but i still get the same problem. depending where i put/call those functions, sometimes javascript doesn’t even think my function exists…
below’s my delete.php file
<?php
require("phpsqlajax_dbinfo.php");
// 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());
}
if(isset($_GET['identifierVar']))
{
$query = 'DELETE FROM markers WHERE name = '.(int)$_GET['identifierVar'];
$result = mysql_query($query);
}
?>
i’ve been testing with just unique names.
like 111, 222, 333.. etc
any help’s appreciated. thanks.
delete from x where name = '$name'. you need to limit to 1, like:delete from x where name = '$name' limit 1