0

I am not sure about understanding about JSON, PHP, and MySQL.

In my plan, I will create a web server and android application.The database server is MySQL. In my understanding, PHP can send data and encode it into a JSON array, how can I use this JSON array in my Android application?

3

2 Answers 2

3

following is PHP code...

<?php
mysql_connect("host","username","password");
mysql_select_db("Deal");
$sql=mysql_query("select * from CITY where CITY_NAME like 'A%'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

here is a nice article link. i hope you like it, and if you have any question, you can ask, i will try to solve it as soon as possible.

Sign up to request clarification or add additional context in comments.

Comments

2

Your question is difficult to understand.

It seems like you're asking how to send JSON data using PHP.

Use the PHP json_encode and json_decode functions to convert between JSON and PHP arrays.

To send a JSON string, first convert the array to JSON using json_encode(), then print the resulting string and exit the program.

<?php
$my_array = array('this'=>'is', 'just'=>'an', 'example'=>'array');

$json_string = json_encode($my_array);
print $json_string;
die;
?>

Hope that helps.

2 Comments

Thank you for ur answer. For your answer that I can conclude, i must send-receive data with server by json_encode and json_decode, right? Actually I really new for all, so it's look complicate in my idea. Can you suggest some documents which can read in more detail for me? Thank you
@Daisy: there's a lot to it, and PHP is just one side of it. Read the PHP manual pages I linked to. Also try Googling for phrases like "json_encode ajax" and similar for tutorials. Here's one I found via Google: prodevtips.com/2008/08/15/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.