Hi I have send and arrayList eventIDBeacon using volley library. I want to ask how to decode the array and store in PhP array variable
Here is my code at android app
private void getEventDetailRespond(RequestQueue requestQueue) {
eventDetail = new ArrayList<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put(Config.EVENT_ID, eventIDBeacon);
//Creating a JSONObject request
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,Config.DATA_URL, new JSONObject(jsonParams),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject respond) {
try {
Toast.makeText(Beacon_MainActivity.this,"eventDetail respond "+respond.toString(),Toast.LENGTH_LONG).show();
eventArray = new JSONArray();
eventArray = respond.getJSONArray("result");
getEventDetail(eventArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Beacon_MainActivity.this, "Unable to fetch data event Detail: " +error.getMessage(),Toast.LENGTH_LONG).show();
}
});
//Adding request to the queue
requestQueue.add(jsonObjectRequest);
}
Here is my PHP server but seem not to work. how to handle ArrayList at server side? im still stuck with this. I want to get back the array and use SQL query to query value in the array and return the result send back to the android app?
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
// decoding the json array
$post = json_decode(file_get_contents("php://input"), true);
$eventID = $post['EventID'];
require_once('dbconnect.php');
$sql = "SELECT EventID, EventTitle, EventDesc, EventTime FROM Event WHERE EVENTID = '$eventID'";
$res = mysqli_query($con,$sql);
$result = array();
while ($row = mysqli_fetch_array($res)){
array_push($result,array(
'EventID'=>$row['EventID'],
'EventTitle'=>$row['EventTitle'],
'EventDesc'=>$row['EventDesc'],
'EventTime'=>$row['EventTime']
));
}
header('Content-Type: application/json');
echo json_encode(array('result'=>$result), 256);
mysqli_close($con);
}
Any help should be much appreciate