Connection.php file which stored database connection code with json:
<?php
$username = "root";
$password = "";
$database = "roadmap";
$url = "localhost";
$con = mysql_connect($url, $username , $password);
if (!$con)
{
die('Could not connect:' . mysql_error());
}
mysql_select_db($database, $con) ;
$data = array();
// query your DataBase here looking for a match to $input
$query = mysql_query("SELECT * FROM students");
while ($row = mysql_fetch_assoc($query)) {
$json = array();
$json['Id'] = $row['Id'];
$json['Lon'] = $row['Lon'];
$json['Lat'] = $row['Lat'];
$data[] = $json;
}
header("Content-type: application/json");
echo json_encode($data);
mysql_close($con);
?>
In separate file index.php:
$.getJSON("connection.php", function(data) {
addMarker( data[0].Lon,data[0].Lat ,data[0].desc);
addMarker(-0.13264,51.50918 , );
addMarker( -0.12498,51.50807 , );
center = bounds.getCenterLonLat();
map.setCenter(center, map.getZoomForExtent(bounds) - 1);
zoom = map.getZoom();
});
this currently pulls the json data through and I have to use it for each individual assigning of a part from the database such as data[0].lon will get the longitude entry for the first record with in the database.
As I am going to be working with quite a few entry's. I want to loop through the json array and then out put all records as so:
addMarker( RECORD 1 );
addMarker( RECORD 2 );
addMarker( RECORD 3 );
Can anyone help me with this.