JSON
JSON

Reputation: 31

How to pass a number from a PHP file into an Android TextView?

I have a PHP file that counts the total amount of rows in a database and outputs 382.

include('connect.php');

$counter = mysql_query("SELECT COUNT(*) AS id FROM records");
$num = mysql_fetch_array($counter);
$count = $num["id"];
echo("$count");

I want to pass that number 382 into a textview in my android activity.

Upvotes: 0

Views: 103

Answers (1)

TN888
TN888

Reputation: 7739

Return that value in JSON format using json_encode($array) and then download it by your Android application, here you have a tutorial : http://www.vogella.com/articles/AndroidJSON/

Example :

$returning = array("Object" => "Value", [...]);
echo json_encode($returning);

Upvotes: 1

Related Questions