如何在Android TextView上不断更新mysql行数?

时间:2013-09-18 18:33:10

标签: php android mysql json

我有一个返回单个数字(即360)的php文件。如何才能将该数字显示在我的android textview中?我只熟悉如何使用如下所示的数组:

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

但我怎么能用一个数字来做。

我创建了自己的php,它创建了一个类似于:

的临时数组
{"success":1,"message":"Post Available!","posts":["records","383"]}

但我错过了大括号:[{“records”,“383”}}}

php是:

<?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));
}

?>

如果有更好的方法来传递一个号码,那将会有所帮助。 感谢。

1 个答案:

答案 0 :(得分:0)

从我用Google搜索来看,TextView不需要输入json编码数据。它可以是字符串或整数。如果我错了,请纠正我?

如果我对,这应该工作:

$counter = mysql_query("SELECT COUNT(*) AS id FROM users");
   $nums = mysql_fetch_array($counter);
  @mysql_close();

  die($nums["id"]);

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