1

I'm doing an app that interacts with a mysql database with some php scripts. I would like to know if it is possible to send and array in a php POST from an android activity ?

This is th code I'm using for the moment :

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("userID", String.valueOf(userID)));

but I think sending and array would be much better than sending one ID at a time.

0

2 Answers 2

3

I would generate a JSON/XML document. You can easily generate especially JSON objects in Android platform.

There are many examples about generating JSON in Android and reading/parsing JSON in PHP.

Hope this helps.

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

Comments

0

I saw a part of the solution in here :

enter link description here

In his example he simply does a for loop like this :

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            //friendID is an array of friends ID   
    for (int i=0;i<friendID.length;i++){
        nameValuePairs.add(new BasicNameValuePair("userAsked[]", String.valueOf(friendID[i])));

    }

The thing is : how do I use it in my php file ? Is it as simple as that :

$asked[] = $_POST['userAsked[]'];

Seems a little bit too easy :s

3 Comments

I think, It is not ideal way. I recommend you to follow a standart way whatever you do. It will be easier to maintenance your code when you need to.
What is the standard way :p would that : for (int i=0;i<friendID.length;i++){ nameValuePairs.add(new BasicNameValuePair("userAsked["+i+"]", String.valueOf(friendID[i]))); } be good :p ?
Standard way to pass data between platforms or via internet is to use XML/JSON in my opinion, if you really curious about.

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.