0

我有一个在线的 mySQL 数据库。我可以更新分数,而且效果很好。现在我想向 Android 返回一个行号,但我做不到。我的 php 文件:

 <?php

$name = $_REQUEST['jugador'];
$score = $_REQUEST['score'];
$moles = $_REQUEST['topos']; 

$con = mysql_connect("hots","db","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("a5385197_scores", $con);

mysql_query("INSERT INTO scores VALUES (null, '$name', $score, $moles)");

$result = mysql_query("SELECT COUNT(1) FROM scores WHERE score >= $score");

echo json_encode($result);

mysql_close($con);
 ?>

插入工作正常,Select 语句返回正确值,但我无法发送到 Android。我要响应的 Android 代码:

        try {
             BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
             StringBuilder sb = new StringBuilder();
             String line = null;
             while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
             }
             is.close();

             result = sb.toString();
             Log.i("miTraza","Recive: "+result);
        }catch(Exception e){
                Log.e("miError", "Error converting result "+e.toString());
        }

结果我得到一个错误:

10-30 01:13:29.445: I/miTraza(29304): Recive: <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
10-30 01:13:29.445: I/miTraza(29304): <b>Warning</b>:  [json] (php_json_encode) type is unsupported, encoded as null in <b>/home/a5385197/public_html/try.php</b> on line <b>21</b><br />
10-30 01:13:29.445: I/miTraza(29304): <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>null
10-30 01:13:29.445: I/miTraza(29304): <!-- Hosting24 Analytics Code -->
10-30 01:13:29.445: I/miTraza(29304): <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
10-30 01:13:29.445: I/miTraza(29304): <!-- End Of Analytics Code -->

我从 PHP 开始,所以很容易出错。

谢谢你的帮助。

4

1 回答 1

2

echo json_encode(mysql_fetch_array($result));

于 2012-10-30T00:37:14.390 回答