title: Mysql + PHP + Google Maps Api
body: <p>I have a database containing records of coordinates for squares. </p>
  
  <p>using <strong>google maps api</strong> I would like to use the records on the database to draw the polygons.</p>
  
  <p>I have some experience with PHP, and was thinking I could use PHP to pass database data to JavaScript.</p>
  
  <p>I assume this can be done with XML, if so, would I write PHP to access the database and load the data into memory </p>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>require_once 'login.php';
  $connection = new mysqli($db_hostname, $db_username, $db_password, $db_database);
  if ($connection-&gt;connect_error) die ($connection-&gt;connect_error);
  
  $query = "SELECT * FROM BC_BBA_SquaresCoordinates";
  $result = $connection-&gt;query($query); 
  if (!$result) die ($connection-&gt;error);
  
  $rows = $result-&gt;num_rows;
  
  for($j=0;$j&lt;$rows;++$j){
      $result-&gt;data_seek($j);
      $row = $result-&gt;fetch_array(MYSQLI_ASSOC);
  }
  $result-&gt;close(); 
  $connection-&gt;close();
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>downloadUrl("test1.php", function(data){
      var xml = data.responseXML;
      var row = xml.documentElement.getElementsByTagName("row");
      for (var i = 0; i &lt; row.length; i++){
        var squarenum = row[i].getAttribute("SQUARE_ID");
      }
  });
  </code></pre>
  
  <p>I am not overly familiar with XML so possibly I am not coding the PHP correctly.  Any help with this would be greatly appreciated.</p>