私のAndroidでは:
String cat_id = getIntent().getExtras().getString("category_id");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("cat_id", cat_id));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.---.com/items.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
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());
}
私のPHPでは:
// editing out DB connections which have been verified to work
<?php
$sql=mysql_query("SELECT * FROM items WHERE cat_id = '".$_REQUEST['cat_id']."'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
したがって、私の問題は、何も返さないことです(JSON結果部分で-トーストには「アイテムが見つかりません」と表示されます)。Android から PHP にパラメータを渡す方法は正しいですか?