I'm trying to send a string and returns json array of objects in response like like this:
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.optString("fullname"));
movie.setThumbnailUrl(obj.optString("image"));
movie.setRating(obj.optString("location"));
movie.setYear(obj.getInt("id"));
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
// adapter.notifyDataSetChanged();
adapter.reloadData();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("fullname", "test"); // fullname is variable and test is value.
return params;
} };
In above code fullname is variable and test is value and using that variable I'm trying to send my variable data in my php variable and perform my query like this:
<?php
header("content-type:application/json");
require_once("dbConnect.php");
$fullname = $_REQUEST["fullname"];
//echo $fullname."11";
$sql = "SELECT id ,image,fullname,location from uploadfinding WHERE fullname like '%$fullname%'";
$res = mysqli_query($conn,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result, array(
"id"=>$row["id"],
"fullname"=>$row["fullname"],
"image"=>$row['image'],
"location"=>$row["location"]));
//echo " over";
}
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($result));
fclose($fp);
echo json_encode($result);
mysqli_close($conn);
?>
But my value test not transfer in php variable $fullname. So problem is how to transfer value test to php variable $fullname.