1

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.

  • Check this related question: http://stackoverflow.com/questions/16545378/how-can-i-fetch-data-from-a-web-server-in-an-android-application. It also recommends tutorial on [How to connect Android with PHP, MySQL](http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/). – abielita May 16 '16 at 06:40
  • its not an issue with connecting to a webserver its updating information from a webserver at set intervals – George Williams Sep 17 '16 at 07:06

0 Answers0