I have followed his popular tutorial to connect Android to MySQL:
http://www.helloandroid.com/tutorials/connecting-mysql-database
It is great at encoding the data back in JSON and displaying rows of data.
My question: What id I want to return just a single value, a single varaible from PHP to Java?
Here is my PHP:
$sql="SELECT AVG(rating) FROM ratings WHERE item_id = 1";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
echo $row[0];
I want to send that last “echo” back to Android, on the guidelines of that tutorial above, how would I do this?
$row is an array and it should have a value like:
All you need to do is throw the
json_encodefunction around row and echo it outThis should get you the single value json encoded string that the java code can read.