title: How to get values from mysql database using php script in android
body: <p>i can not fetch data from mysql database. i maked an android app which connect to mysql db and fetch data using php script....
  when i run code it throws exception string cannot convert to jsonarray....
  Also guide me where i put my php script in XAMP 
  PHP script:</p>
  
  <pre><code>$con = mysql_connect("localhost","root","");
   if (!$con)
   {
     die('Could not connect: ' . mysql_error());
   }
   mysql_select_db("login",$con);
   $sql=mysql_query("SELECT * FROM category ORDER BY `category`.`category` ASC");
   while($row=mysql_fetch_assoc($sql))
   $output[]=$row;
    print(json_encode($output));
    mysql_close($con);
  </code></pre>
  
  <p>Code:-</p>
  
  <pre><code>tv=(TextView)findViewById(R.id.textView1);
      String result = null;
      InputStream is = null;
      StringBuilder sb = null;
      ArrayList nameValuePairs = new ArrayList();
      List r = new ArrayList();
      try{
      //http post
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost("http://ip../xampp/htdocs/db.php");
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      HttpResponse response = httpclient.execute(httppost);
      HttpEntity entity = response.getEntity();
      is = entity.getContent();
      }
      catch(Exception e){
      Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
      }
      //Convert response to string
      try
      {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
      sb = new StringBuilder();
      String line = null;
      while ((line = reader.readLine()) != null)
      {
      sb.append(line +"\n");
      }
      is.close();
      result = sb.toString();
      }
      catch(Exception e)
      {
      Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
      }
      //END Convert response to string
      try{
      JSONArray jArray = new JSONArray(result);
      JSONObject json_data=null;
      for(int i=0;i&lt;jArray.length();i++) {
      json_data = jArray.getJSONObject(i);
      tv.append(json_data.getString("category").toString()+"\n");
      }
  
      }
      catch(JSONException e1){
      Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
      Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
      }
  </code></pre>