0

I have a simple understanding of how this sample app should work. I have a MySQL DB a PHP script on my server and some code in my Android application. From the information I've gathered from StackOverflow and other sources, it seems like the best way to get data from my DB is to send my PHP script some parameters (from my app)of what data I want, and then relay that information back to the app.

As of right now, my android app is just using a httppost method to connect to a URI of the PHP page. It is simply reading the webpage of plaintext and spitting it back onto the screen. My question is, how do I go about sending some kind of formatted output back to my application so that I can sort it, and put different parts of the response into different parts of my app.

Example:

DB:

Menu ID| Dinner | Desert|

 1 | Chicken| Jello |
 2 | Steak  | Fruit |
 3 | Ham    | Cake  |

PHP: Take parameter (http://website.com/script.php?param=1) Look it up in DB and echo that row.

Android: Send httppost to URI Take the input and show it on the screen

So what is the best way that I could seperate the incoming data?

Example: This is from Menu: 1 You dinner will be: Chicken Your desert will be: Jello

Basically how can I "parse" the data? I feel like there should be a standard way (but I'm just not sure about it yet)

2 Answers 2

2

Maybe use JSON in both ends. Easiest way to handle data structures and both PHP and Android have very good APIs for usage:

http://php.net/manual/en/book.json.php

http://developer.android.com/reference/org/json/package-summary.html

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

2 Comments

Seems like JSON is the way to go. Is this the "standard" for most applications for doing something like I would like to accomplish?
JSON is standardized and supported by most of the platforms natively. If some platform does not have support (which is unlikely) it is quite easy to write your own parser for JSON data. Check out more at wikipedia or just google it en.wikipedia.org/wiki/JSON
0

Using Phonegap jquery mobile, it will be very easy to handle php-mysql pages. You can use JSONP also.

steps:

  1. Start the JSONP or Ajax request from html page to the php server page and process the mysql db data and return back the responses to the html page.

1 Comment

I do not want to use phonegap. Sorry, it's a viable option in the future. I want to learn how to do it "from-scratch" first.

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.