Which code snipplets in PHP can create a input form, which creates a new set of data in my mysql dat
Posted
by smiyazaki
on Stack Overflow
See other posts from Stack Overflow
or by smiyazaki
Published on 2010-05-22T17:24:44Z
Indexed on
2010/05/22
17:30 UTC
Read the original article
Hit count: 144
I am using the Google Maps API with parts in javascript and others in PHP.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Google Maps AJAX + mySQL/PHP Example //
var iconBlue = new GIcon();
iconBlue.image = 'icon.png';
iconBlue.shadow = '';
iconBlue.iconSize = new GSize(19, 19);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);
var iconRed = new GIcon();
iconRed.image = 'icon.png';
iconRed.shadow = '';
iconRed.iconSize = new GSize(19, 19);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);
var customIcons = [];
customIcons["restaurant"] = iconBlue;
customIcons["bar"] = iconRed;
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setMapType(G_SATELLITE_MAP);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(47.614495, -122.341861), 13);
// Change this depending on the name of your PHP file
GDownloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point, name, address, type);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, name, address, type) {
var marker = new GMarker(point, customIcons[type]);
var html = "<b>" + name + "</b> <br/>" + address;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
(I suppose the php will be called by "GDownloadUrl("phpsqlajax_genxml.php", function(data) { ..." in the javascript part of the sourcecode of phpsqlajax_map.htm)
Now I need another php file and the code snipplets for it, which creates an input form where I can add some new locations to the google map. Following code is used to create the xml file here: http://detektors.de/maptest/phpsqlajax_genxml.php The next step would be, trying to make an plugin for wordpress that I could easily post a blog entry with a new location on the same map, which displays already some other locations stored in the mysql database.
thanks!
<?php
require("phpsqlajax_dbinfo.php");
function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",''',$xmlStr); $xmlStr=str_replace("&",'&',$xmlStr); return $xmlStr; }
// Opens a connection to a MySQL server $connection=mysql_connect ($host, $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()); }
// Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); }
header("Content-type: text/xml");
// Start XML file, echo parent node echo '';
// Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo ''; }
// End XML file echo '';
?>
© Stack Overflow or respective owner