Hi I'm having some problems making my function structure. Would appreciate any help.
First this function should delete map markers once OnChange event is triggered from index.php.
And send post values to xmlmapquery.php for data retrieval.
once retrieved, The data should be stored back to my index.php in <div id='content'>
function filter()
{
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
var lgu = $('#lgu').val();
var category = $('#category').val();
var type = $('#type').val();
$.get('xmlmapquery.php', { filter: lgu, filter2: category, filter3: type},function(data){
$('#content').text(data);
)};
};
Now this is xmlmapquery.php
<?php
include('connection_db.php');
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
if(isset($_POST['filter']) && isset($_POST['filter2']) && isset($_POST['filter3'])){
$query = "SELECT * FROM markers WHERE type='".$_POST['filter']."' and type='".$_POST['filter2']."'
and type='".$_POST['filter3']."'";
}
// Select all the rows in the markers table
$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)){
// ADD TO XML DOCUMENT NODE
$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("type", $row['type']);
}
echo $dom->saveXML();
?>
Would appreciate help on this. currently the function is NOT working even deleting the markers is not working. Once i get this thing working I will add more commands to the function that would get data and create new markers for my map. Thanks in advance.
mysql_real_escape_string()on each of those$_POSTquery inputs. Ideally though, consider switching to a newer API that supports prepared statements, like MySQLi or PDO. Themysql_*()functions will be deprecated in the next major PHP version 5.5<select>elements I think they would be secure.mysql_real_escape_string()But I'll move to MySQLi In the near future. As i said I'm new to javascript I will try that console.log. Thanks for the tips.