title: Android external online database
body: <p>i have an online database in phpMyAdmin. At this time I can query him and I can get the result in a TextView but i want to get the value of each cell, how do I?</p>
  
  <p>This is an example</p>
  
  <pre><code>[{"Monday":"","Tuesday":"","Wednesday":"","Thursday":"","Friday":"","Saturday":"","Sunday":"","id":"","info":""},...]
  </code></pre>
  
  <p>I would like to get the value of Monday for example.</p>
  
  <p>Thanks</p>
  
  <p>code sendQuery.java:</p>
  
  <pre><code> public class sendQuery {
  /////////// Public method to send Query ///////////
  public static String send(String query) {
      String result = "0";
      InputStream is = null;
      String weekDayVal;
      //the query to send
      ArrayList&lt;NameValuePair&gt; querySend = new ArrayList&lt;NameValuePair&gt;();
  
      querySend.add(new BasicNameValuePair("querySend",query));
  
      //http post
      try{
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://locali.altervista.org/php/locali.php");
          httppost.setEntity(new UrlEncodedFormEntity(querySend));
          HttpResponse response = httpclient.execute(httppost);
          HttpEntity entity = response.getEntity();
          is = entity.getContent();
      }catch(Exception e){
          Log.e("log_tag", "Error in http connection "+e.toString());
      }
  
      //convert response to string
      try{
          BufferedReader reader = new BufferedReader(
                  new InputStreamReader(is,"iso-8859-1"),8);
          StringBuilder sb = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
          is.close();
          result=sb.toString();
          try{
              JSONArray weekDetails = new JSONArray ( result); // Your response string
              for(int index=0;index &lt; weekDetails.length();index++)
              {
              JSONObject tempWeekDetail = weekDetails.getJSONObject(index);
              weekDayVal = tempWeekDetail.getString("Monday");// Value for Monday
              //added this Log which you can view from LogCat. also changed above variable name
              Log.i("Resp Value"," Moday Value"+weekDayVal);
              }
              }catch(Exception e)
              {
              //catch exception here
              }
      }catch(Exception e){
          Log.e("log_tag", "Error converting result: "+e.toString());
      }
  
      Log.i("SendQUERY", result);
      return result;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>main.java:</p>
  
  <pre><code> public class main extends Activity {
  /** Called when the activity is first created. */
  @Override
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      TextView resLayout = (TextView) findViewById(R.id.res);
  
  
      String res = sendQuery.send("SELECT * FROM contatti");
  
      resLayout.append(res);
  
  
  }
  }
  </code></pre>