How to display external database contents in android and assign it to the local variable
<p>database fields are</p>

<p><strong>phone_no</strong>       ||         <strong>count</strong> <br/>
999999999          ||           1     <br/>
777777777          ||           2   <br/></p>

<p>I have created phone_no activity such that if I enter the phone number it should display the count according to that phone_no below</p>

<p>My code is as follows</p>

<pre><code>{
HttpClient httpclient = new DefaultHttpClient();   
HttpPost httppost = new HttpPost("http://10.0.2.2/phoneno.php");

String pho = input.getText().toString();

List&lt;NameValuePair&gt; nameValuePairsphedit = new ArrayList&lt;NameValuePair&gt;(11);

nameValuePairsphedit.add(new BasicNameValuePair("phone_no",pho));

try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsphedit));
Log.d("myapp", "works till here. 2");

 try {
         HttpResponse response = httpclient.execute(httppost);
         Log.d("myapp", "response " + response.getEntity());
         String result = EntityUtils.toString(response.getEntity());
         Log.d("","Response :"+result);
         JSONObject json=new JSONObject(result);

         count1 = json.getString("count");//count1 is local variable

     } 
catch (Exception e) 
{
     e.printStackTrace();
} 
                    }
</code></pre>

<p>And my phoneno.php file is as follows</p>

<pre><code>&lt;?php

$conn= mysql_connect('localhost','root','');
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }

    mysql_select_db('test',$conn);


    $phone_no = mysql_escape_string($_REQUEST['phone_no']);

    $sql="SELECT * FROM meh WHERE phone_no='$phone_no'";
    $result = mysql_query($sql) or die(mysql_error());
    if (!$result)
    {
        die('There was a problem executing the query');
    }
    else
    {

    $rs=mysql_fetch_array($result);

    $arrInfo = array('phone_no' =&gt; $rs['phone_no'] , 'count' =&gt; $rs['count']);

    echo json_encode($arrInfo);

    }
?&gt;
</code></pre>
