I get the "No Items found" toast on the ListActivity.
Note: When I change the PHP code to "Select * from items", the entire table shows up. But when I try to filter it with the param/cat_id value in Android/Java, I get a blank
Here is code, first: php
<?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();
?>
(I have confirmed that "cat_id", the value I am passing into the below activity through a bundle is what it needs to be.)
Android/Java:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cat_id = getIntent().getExtras().getString("category_id");
items = new ArrayList<String>();
new task().execute();
}
class task extends AsyncTask<String, String, Void> {
@Override
protected Void doInBackground(String... params) {
String url_select = "http://www.---.com/---/items.php";
param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("category_id", cat_id));
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_select);
try {
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// read content
is = httpEntity.getContent();
} catch (Exception e) {
//
}
and farther below
protected void onPostExecute(Void v) {
String item;
try {
jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
item = json_data.getString("item");
items.add(item);
}
} catch (JSONException e1) {
Toast.makeText(getBaseContext(), "No Items Found",
Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
I get the "No Items found" toast on the ListActivity.
Note: When I change the PHP code to "Select * from items", the entire table shows up. But when I try to filter it with the param/cat_id value in Android/Java, I get a blank.