pistonhead Posted March 9, 2010 Share Posted March 9, 2010 Hi I'm making a map application, and I'm trying to loop through all the entries in the MySQL database, retrieve the latitude and longitude variables, and then place them on a map. Problem is, I can't place the map markers inside the PHP, and I can't access the variables declared in the PHP outside the brackets. Using the variables outside the PHP would mean only the last entry in the database is displayed on the map, since the loop is already done. <?php $connection = mysql_connect("ramen.cs.man.ac.uk", "*****************", "********************") or die('Could not connect: ' . mysql_error()); mysql_select_db("*************", $connection) or die('Could not select database'); $result = mysql_query("SELECT * FROM AttractionLocation"); while($row = mysql_fetch_array($result)) { $Lat= $row['AttractionLatitude']; $Long= $row['AttractionLongitude']; $AttractionID= $row['AttractionID']; $result2 = mysql_query("SELECT * FROM AttractionName WHERE AttractionID = $AttractionID"); while($row = mysql_fetch_array($result2)) { $AttractionName= $row['AttractionName']; } } mysql_close($connection); ?> Here is the code which I want to include inside the while loop within the PHP: // Big Ben var point = new GLatLng(51.5007, -0.124261); var marker = createMarker(point,'<div style="width:240px">This is the location of Big Ben.<br /><img border="0"src="markers/bigben/bigben.jpg"width="240" height="200" /><br /> With a <a href="http://en.wikipedia.org/wiki/Big_ben">Link<\/a> to the bigben wikipedia page<\/div>') map.addOverlay(marker); Any help would be appreciated. Thankyou Link to comment https://forums.phpfreaks.com/topic/194620-php-mysql-html-problem/ Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 You mean like this? <?php $connection = mysql_connect("ramen.cs.man.ac.uk", "*****************", "********************") or die('Could not connect: ' . mysql_error()); mysql_select_db("*************", $connection) or die('Could not select database'); $result = mysql_query("SELECT * FROM AttractionLocation"); while($row = mysql_fetch_array($result)) { $Lat= $row['AttractionLatitude']; $Long= $row['AttractionLongitude']; $AttractionID= $row['AttractionID']; ?> var point = new GLatLng($Lat, $Long); var marker = createMarker(point,'<div style="width:240px">This is the location of Big Ben.<br /><img border="0"src="markers/bigben/bigben.jpg"width="240" height="200" /><br /> With a <a href="http://en.wikipedia.org/wiki/Big_ben">Link<\/a> to the bigben wikipedia page<\/div>') map.addOverlay(marker); <?php $result2 = mysql_query("SELECT * FROM AttractionName WHERE AttractionID = $AttractionID"); while($row = mysql_fetch_array($result2)) { $AttractionName= $row['AttractionName']; } } mysql_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/194620-php-mysql-html-problem/#findComment-1023638 Share on other sites More sharing options...
jl5501 Posted March 9, 2010 Share Posted March 9, 2010 <?php $connection = mysql_connect("ramen.cs.man.ac.uk", "*****************", "********************") or die('Could not connect: ' . mysql_error()); mysql_select_db("*************", $connection) or die('Could not select database'); $result = mysql_query("SELECT * FROM AttractionLocation"); while($row = mysql_fetch_array($result)) { $Lat= $row['AttractionLatitude']; $Long= $row['AttractionLongitude']; $AttractionID= $row['AttractionID']; $result2 = mysql_query("SELECT * FROM AttractionName WHERE AttractionID = $AttractionID"); while($row = mysql_fetch_array($result2)) { $AttractionName= $row['AttractionName']; } ?> <?php echo '//'. $AttractionName;?> var point = new GLatLng(<?php echo $Lat.','.$Long;?>); var marker = createMarker(point,'<div style="width:240px">This is the location of <?php echo $AttractionName;?>.<br /><img border="0"src="markers/bigben/bigben.jpg"width="240" height="200" /><br /> With a <a href="http://en.wikipedia.org/wiki/<?php echo $AttractionName;?>">Link<\/a> to the <?php echo $attractionName;?> wikipedia page<\/div>') map.addOverlay(marker); <?php } mysql_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/194620-php-mysql-html-problem/#findComment-1023649 Share on other sites More sharing options...
jl5501 Posted March 9, 2010 Share Posted March 9, 2010 The above answer is assuming you are currently between <script> </script> tags, else you will have to output those as well Link to comment https://forums.phpfreaks.com/topic/194620-php-mysql-html-problem/#findComment-1023652 Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 The above answer is assuming you are currently between <script> </script> tags, else you will have to output those as well Apologize I forgot my echo lol. Link to comment https://forums.phpfreaks.com/topic/194620-php-mysql-html-problem/#findComment-1023653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.