I know how to use Volley GET method for login purposes but what if I need to specify a specific "id"? I am passing the "id" of a list item from a remote database to another activity using intent.putExtra. In the next activity, how would I utilize Volleys' GET method to parse and display data from another table using that passed over "id"?
In a browser I can use the following to get a response with a specified url and parameter:
http://localhost/demoapp/fetch.php?pid=2
But I don't know how to pass that url to a Volley request and display the response in a listview. Something like this:
"http://localhost/demoapp/fetch.php?pid=" + pid
Where "pid" would be the passed over string of the corresponding id.
EDIT:PHP Code
<?php
include_once("config.php");
$query=mysqli_query($con,"SELECT * FROM comments WHERE pid=".$_GET['pid']);
$array;
while($result=mysqli_fetch_assoc($query)){
$array[]=$result;
}
echo json_encode($array);
?>
EDIT 2: JAVA Code Main Activity
JsonArrayRequest request = new JsonArrayRequest(url+url_file,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString()); try {
for(int i=0;i<response.length();i++){
String pid=response.getJSONObject(i).getString("pid");
String name=response.getJSONObject(i).getString("product_name");
String img;
String thumb = response.getJSONObject(i).getString("product_thumb");
String detail = response.getJSONObject(i).getString("product_detail");
String rating = response.getJSONObject(i).getString("product_rating");
img = response.getJSONObject(i).getString("product_pic");
rowdata.add(new ProductRowData(pid,name,img,thumb,detail,rating));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
adapter=new ProductsAdapter(MainActivity.this, rowdata);
list.setAdapter(adapter);
dialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " + error.getMessage());
dialog.dismiss();
}
});
VolleyController.getInstance().addToRequestQueue(request, tag_json_arry);
When list item is clicked, rest of data is passed over to detail activity using intent.putExtra. What I am then trying to do is, upon clicking on FAB, a list of comments from a different table with that products id should be shown.