I am trying to retrieve multiple table rows from an SQL database from a web server and i cant figure out how to retrieve the data from the server.
Response Listener:
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
for(int i = 0; i <= jsonResponse.length();i++){
final Marker marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(jsonResponse[i][1], jsonResponse[i][2]))
);
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(UserArea.this);
builder.setMessage("Update Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
PHP:
<?php
include "connect/connection.php";
$query = "SELECT * FROM positions";
$resualt = mysql_query($query);
$responce = array();
$responce["success"] = true;
while($i = mysql_fetch_assoc($resualt)){
$responce[] = array($i["username"], $i["Lat"], $i["Lng"]);
}
echo json_encode($responce);
?>
essentially i am trying so place table data into an array, and then send it to the android class where the data can be used to place makers on a Google Maps Fragment. I cannot seem to figure out how to do this. Any help would be really appreciated.