• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to get constantly updating mysql row count onto Android TextView?

jsonman

Lurker
I have a php file that returns a single number (i.e. 360). How can I get that number to appear in my android textview? I am only familiar with how to do this with arrays that look like this:

{"success":1,"message":"Post Available!","posts":[{"name":"John Smith","id":"1"}, ...]}

but how can I do it with just a single number.

I made my own php that makes a makeshift array that looks like:

{"success":1,"message":"Post Available!","posts":["records","383"]}

but I am missing the curly brackets :[{"records","383"}]}

the php is:
<?php

include('connect.php');

$counter = mysql_query("SELECT COUNT(*) AS id FROM users");
$nums = mysql_fetch_array($counter);
$count = $nums["id"];

$other["records"] = "records";
$other["counter"] = $count;


if ($nums) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"] = array();

for ($x=0; $x<=0; $x++){

//update our repsonse JSON data
array_push($response["posts"], $other["records"], $other["counter"]);
}

// echoing JSON response
echo json_encode($response);

} else {
$response["success"] = 0;
$response["message"] = "No Post Available!";
die(json_encode($response));
}

?>

If there is a better way to just pass one number, that would be helpful.
Thanks.
 
Back
Top Bottom