数据库字段是
电话号码 || 数
999999999 || 1
777777777 || 2
我创建了 phone_no 活动,这样如果我输入电话号码,它应该根据下面的 phone_no 显示计数
我的代码如下
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/phoneno.php");
String pho = input.getText().toString();
List<NameValuePair> nameValuePairsphedit = new ArrayList<NameValuePair>(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();
}
}
而我的phoneno.php文件如下
<?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' => $rs['phone_no'] , 'count' => $rs['count']);
echo json_encode($arrInfo);
}
?>