title: Parsing json data to a table but some rows are not fetched
body: <p>I am using google maps api to get an address based on a given longitude and latitude. There can be several calls to the api, the longitudes and latitudes are loaded from a database.</p>
  
  <p>I want to go through all the api calls and get the formatted address and display it in a table. </p>
  
  <p>The table layout is as follows: count / ref / longitude / latitude / address</p>
  
  <p>My script is as follows:</p>
  
  <pre><code>&lt;?php
  $databasehost = "localhost";
  $databasename = "...";
  $databasetable = "import1";
  $databasetable2 = "data1";
  $databaseusername ="...";
  $databasepassword = "...";
  
  
  $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
  @mysql_select_db($databasename) or die(mysql_error());
  
  $query = mysql_query("SELECT * from $databasetable;");
  
  $data = array();
  
  $index = 0;
  while($row = mysql_fetch_assoc($query))
  {
       $data[$index] = $row;
       $index++;
  }
  $count = 1;
  ?&gt;
  &lt;table&gt;
  &lt;?php
  foreach ($data as $key) {
      $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$key['latitude'].','.$key['longitude'].'&amp;sensor=true';
      $json = file_get_contents($url);
      $dataReceived = json_decode($json, TRUE);
  
      if(!empty($dataReceived['results'][0]['formatted_address']))
      {
          $formattedAddress = $dataReceived['results'][0]['formatted_address'];
      }else{
          $formattedAddress = '';
      }
      ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?=$count?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$key['id']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$key['latitude']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$key['longitude']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$formattedAddress?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php
      $count++;
  }
  ?&gt;
  &lt;/table&gt;
  &lt;?php
  @mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>Now, if you go to this link: <a href="http://www.ryansmurphy.com/crawler/get-data.php" rel="nofollow">http://www.ryansmurphy.com/crawler/get-data.php</a> the problem becomes clear. Some rows, dont have an address. IF you keep refreshing youll notice that it seems to be different rows each time that dont have an address. Its extremely odd. </p>
  
  <p>If you take one of the rows that doesnt have an address and put the longitude and latitude into the api call, (see the link to the api call in the script above) youll notice there is data for the formatted address. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>All of the rows should returning the address.</p>