Jump to content

problem with variable variables


kez1985

Recommended Posts

function view_map()
{
echo "<html><head><title>Map!</title></head>
<body onload=\"load()\" style=\"margin:15px; background-color: #ffffff;\">";
$connection = connect();
$sql = "SELECT * FROM mapdata WHERE 1";
$result = mysql_query($sql) or die(mysql_error());
$n = 0;
echo "\n<script type=\"javascript\">";
while($rows = mysql_fetch_assoc($result))
{
	echo "\n";
	foreach($rows as $k => $v)
	{
		if($k != "id")
		{
			$$k[$n] = stripslashes($v);                           //the bit that isn't working!! :-(
		}
	}
	$n++;
}
echo "\n</script>";
$centrelat = "50.8229";
$centrelong = "-0.1442";
echo "
<noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b> However, it seems JavaScript is either disabled or not supported by your browser. To view Google Maps, enable JavaScript by changing your browser settings or download a javascript enabled browser, and then try again.
</noscript>
<script src=\"http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAG9hPptHITJl7waZW2RKQmRRgvzeIN_2NkkM3M_fNBFDhsKT4fhQwaqd1iXCBbOMLmRV8QPtMJ9CkUw\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">
//<![CDATA[
var map;
function createMarker(point,icon,html) {
  var marker = new GMarker(point,icon);
  GEvent.addListener(marker, \"click\", function() {
	marker.openInfoWindowHtml(html);
  });
  return marker;
}
function load() { 
	if (GBrowserIsCompatible()) { 

	  map = new GMap2(document.getElementById(\"map\"));
	  map.setCenter(new GLatLng(".$centrelat.",".$centrelong."),16);
	  
	  var point = new GLatLng(50.8194,-0.1294);
	  var marker = createMarker(point, '','<div style=\"width:200px; height: 30px;\"><u>Blanch House</u><br />17 Atlingworth Street<br />Brighton<br />East Sussex<br />BN2 1PL</div>');
	  map.addOverlay(marker);
	  map.addControl(new GSmallMapControl());
	  
	  var CPIcon = new GIcon();
	  CPIcon.image = \"http://absolutebrighton.tv/maps/parkingtop.png\";
	  CPIcon.shadow = \"http://absolutebrighton.tv/maps/parkingshadow.png\";
	  CPIcon.iconSize = new GSize(50, 40);
	  CPIcon.shadowSize = new GSize(50, 40);
	  CPIcon.iconAnchor = new GPoint(37, 59);
	  CPIcon.infoWindowAnchor = new GPoint(31, ;
	  
	  var TSIcon = new GIcon();
	  TSIcon.image = \"http://absolutebrighton.tv/maps/traintop.png\";
	  TSIcon.shadow = \"http://absolutebrighton.tv/maps/trainshadow.png\";
	  TSIcon.iconSize = new GSize(50, 35);
	  TSIcon.shadowSize = new GSize(50, 35);
	  TSIcon.iconAnchor = new GPoint(37, 59);
	  TSIcon.infoWindowAnchor = new GPoint(31, ;
	  
	  var cp1 = new GLatLng(50.8243,-0.1404);
	  var cp1marker = createMarker(cp1,CPIcon,'<div style=\"width:200px; height: 40px;\">Church St NCP Mspc<br />Church St, Jew Street<br />Brighton,<br>BN1 1US<br /><br />0870 606 7050</div>');
	  map.addOverlay(cp1marker);";
	  $n=0;
	  while($n != sizeof(mysql_num_rows($result)))
	  {
		echo "\n \\test test test";
		echo "\n var cp".$n." = new GLatLng($latitude[$n],$longitude[$n]);
	\n var cp".$n."marker = createMarker(cp".$n.",CPIcon,'<div style=\"width:200px; height: 40px;\">$location_name[$n]<br />$address_1[$n]<br />$town[$n]<br>$postcode[$n]<br /><br />0870 606 7050</div>');
	  map.addOverlay(cp".$n."marker);";
	  $n++;
	  }
	echo "}
	// display a warning if the browser was not compatible
	else {
	  alert(\"Sorry, the Google Maps API is not compatible with this browser\");
	}
}
</script>
<div id=\"map\" style=\"width: 522px; height: 400px; left: 0px; top:0px; bottom:7px; right:0px; display: block;\"></div>";
}

 

ok, so I'm trying to develop a php/mysql based google map generator, there is already the interface for adding new locations into the database but I've got stuck on how to display the map. I thought the best way would be to pull the data out of the database and set the field key as the variable name (as there are only a few fields) and then I could do a foreach to put the data into a code variable...this is probably not the way and I would invite any help on a better way of doing this as I was just being quick and dirty and also am relatively new to php...I kinda see this as an expandable project which shouldn't be too hard to get my teeth into and get me used to writing php. So if anyone can help it would be really appreciated.

 

kind regards, Kerry

Link to comment
https://forums.phpfreaks.com/topic/110741-problem-with-variable-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.