I'm doing a project to get started in Android. I'm trying to read from a mySQL database as well as read.
Everything works fine, but I'm just reading one row from the database. 
Does anyone know why? 

Here is my task to read , you just need to look at the call into **Oncreate(),GetAllCostumberTask
and SetTextToview() method**.

```
package com.example.ultimate;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    private TextView responseTextView;
    private EditText eNombre,eApellido,eEdad,eMovil;
    private Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.responseTextView = (TextView) this.findViewById(R.id.responseTextView);
        this.eNombre = (EditText) this.findViewById(R.id.editNombre);
        this.eApellido = (EditText) this.findViewById(R.id.editApellido);
        this.eEdad = (EditText) this.findViewById(R.id.editEdad);
        this.eMovil = (EditText) this.findViewById(R.id.editMovil);
        this.b1 = (Button) this.findViewById(R.id.button1);

        new GetAllCustomerTask().execute(new ApiConnector());

    }
    public void funcion(View v){
        if((eNombre.getText().toString().length()<1)
                ||(eApellido.getText().toString().length()<1)
                ||(eEdad.getText().toString().length()<1)
                ||(eMovil.getText().toString().length()<1)){

            // out of range
            Toast.makeText(this, "please enter something", Toast.LENGTH_LONG).show();
        }else{
            String[] lista = new String[4];

            lista[0] = eNombre.getText().toString();
            lista[1] = eApellido.getText().toString();
            lista[2] = eEdad.getText().toString();
            lista[3] = eMovil.getText().toString();
            new MyAsyncTask().execute(lista);       
        }
    }

    public void setTextToTextView(JSONArray jsonArray)
    {
        String s  = "";

        for(int i=0; i<jsonArray.length();i++){

            JSONObject json = null;
            try {
                json = jsonArray.getJSONObject(i);
                s = s +
                        "Name : "+json.getString("FirstName")+" "+json.getString("LastName")+"\n"+
                        "Age : "+json.getInt("Age")+"\n"+
                        "Mobile Using : "+json.getString("Mobile")+"\n\n";
               // Toast.makeText(getApplicationContext(), "paso", Toast.LENGTH_LONG).show();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        this.responseTextView.setText(s);

    }

    private class MyAsyncTask extends AsyncTask<String, Integer, Double>{

        @Override
        protected Double doInBackground(String...  params) {
            // TODO Auto-generated method stub
            postData(params);
            return null;
        }

        protected void onPostExecute(Double result){

            Toast.makeText(getApplicationContext(), "command sent", Toast.LENGTH_LONG).show();
        }
        protected void onProgressUpdate(Integer... progress){

        }

        public void postData(String[] valueIWantToSend) {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://accessibility.es/prueba/insert.php");

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("FirstName", valueIWantToSend[0]));
                nameValuePairs.add(new BasicNameValuePair("LastName", valueIWantToSend[1]));
                nameValuePairs.add(new BasicNameValuePair("Age", valueIWantToSend[2]));
                nameValuePairs.add(new BasicNameValuePair("Movil", valueIWantToSend[3]));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);

            } catch (ClientProtocolException e) {
                Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
            }catch(Exception e){
                Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
            }
        }

    }

    private class GetAllCustomerTask extends AsyncTask<ApiConnector,Long,JSONArray>
    {
        @Override
        protected JSONArray doInBackground(ApiConnector... params) {

            // it is executed on Background thread

             return params[0].GetAllCustomers();
        }

        @Override
        protected void onPostExecute(JSONArray jsonArray) {

            setTextToTextView(jsonArray);

        }
    }

```

}

**Here is my ApiConnector**

```
package com.example.ultimate;

import android.util.Log;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;

public class ApiConnector {

    public JSONArray GetAllCustomers()
    {
        // URL for getting all customers

        String url = "http://accessibility.es/prueba/script.php";

        // Get HttpResponse Object from url.
        // Get HttpEntity from Http Response Object

        HttpEntity httpEntity = null;

        try
        {

            DefaultHttpClient httpClient = new DefaultHttpClient();  // Default HttpClient
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);

            httpEntity = httpResponse.getEntity();

        } catch (ClientProtocolException e) {

            // Signals error in http protocol
            e.printStackTrace();

            //Log Errors Here

        } catch (IOException e) {
            e.printStackTrace();
        }

        // Convert HttpEntity into JSON Array
        JSONArray jsonArray = null;

        if (httpEntity != null) {
            try {
                String entityResponse = EntityUtils.toString(httpEntity);

                Log.e("Entity Response  : ", entityResponse);

                jsonArray = new JSONArray(entityResponse);

            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return jsonArray;

    }

}

```

**And the php script with default values. Sorry, forgot about it**

```
<?php 

$con = $con = mysql_connect("localhost","xxxx","xxxx");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("TestDatabase", $con);

$result = mysql_query("SELECT * FROM Customer");

while($row = mysql_fetch_assoc($result))
  {
 $output[]=$row;
  }

print(json_encode($output));

mysql_close($con);

?>

```

Can't link images due to reputation, I'd like to.

Ok, I'm debugging it right now. And i found that this code is not working as expected. By that I mean, s String is not updating itself, just saving the first row, but not the others.
Anyone sees something wrong with that s = s + ""?

```
for(int i=0; i<jsonArray.length();i++){

                JSONObject json = null;
                try {
                    json = jsonArray.getJSONObject(i);
                    s = s +
                            "Name : "+json.getString("FirstName")+" "+json.getString("LastName")+"\n"+
                            "Age : "+json.getInt("Age")+"\n"+
                            "Mobile Using : "+json.getString("Mobile")+"\n\n";
                   // Toast.makeText(getApplicationContext(), "paso", Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

```