I'm having problems with the following loop, which generates null results for the variable newLat[i]
. However, when I directly populate newLat[0]
(in the last 2 lines) it works fine. Any thoughts?
PHP:
$sql = "SELECT `id`, `name`, `lat`, `lng` FROM `markers` " ;
$result = $dbc->query($sql);
$hits = $result->num_rows ;
echo "<br /> Records = " ;
echo "$hits <br />";
while($row = $result->fetch_assoc()) {
$MarkerID[] = $row['id'];
$MarkerName[] = $row['name'];
$MarkerLat[] = $row['lat'];
$MarkerLng[] = $row['lng'];
}
and Javascript:
var myhits = <?php echo json_encode($hits); ?>;
var newLat = new Array (myhits);
for (var i = 0; i < myhits; i++) {
newLat[i] = <?php echo json_encode($MarkerLat[i]); ?>;
document.write (newLat[i]);
}
newLat[0] = <?php echo json_encode($MarkerLat[0]); ?>;
document.write (newLat[0]);