I'm getting error when i try to get the value of Count(id) of my database. I want to get the value and put him in an textView.
This is my java code (the response is already constructed as an array)
public void test3(View rootView){
String result = null;
try
{
tv = (TextView) rootView.findViewById(R.id.textView);
RequestQueue queue = Volley.newRequestQueue(getActivity().getApplicationContext());
String url = "http://brunos.000webhostapp.com/teste/listar_divisoes.php";
final String finalResult = result;
JsonArrayRequest jsonRequest = new JsonArrayRequest
(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
JSONObject jObj = new JSONObject(finalResult);
String count= jObj.getString("COUNT(id)");
tv.setText(count);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
queue.add(jsonRequest);
}
This is my php code:
<?php
include 'database.php';
$pDatabase = Database::getInstance();
$sql = "SELECT COUNT(id) FROM divisao;";
$result = $pDatabase->query($sql);
$rows = array();
while($temp = mysqli_fetch_assoc($result)) {
$rows[] = $temp;
}
echo json_encode($rows);
?>