Jump to content

PHP MySQL/ HTML problem


pistonhead

Recommended Posts

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. :shrug: 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

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);
      ?>    

<?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);
?>   

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.