Получить нулевые данные, используя залп с параметрами

private void fetchPatients() {
// Creating volley request obj
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("uid", "P001");

JsonObjectRequest req = new JsonObjectRequest(url, new JSONObject(headers),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());

for (int i = 0; i < response.length();i++) {
try {
//Log.d("id","hi1") ;
//Log.d("i","i:"+i);

AppointmentList appointment = new AppointmentList();

//Log.d("length", "length:" + response.length());
JSONObject objuid= response.getJSONObject("uid");

JSONObject objatype= response.getJSONObject("appointment_type");
appointment.setAtype(objatype.getString("appointment_type"));

JSONObject objdoctor= response.getJSONObject("doctor");
appointment.setDoctor(objdoctor.getString("doctor"));

JSONObject objdate= response.getJSONObject("date");
appointment.setDate(objdate.getString("date"));

JSONObject objtime= response.getJSONObject("time");
appointment.setTime(objtime.getString("time"));JSONObject objqueue= response.getJSONObject("queue");
appointment.setQueue(objqueue.getInt("queue"));

appointmentList.add(appointment);

// updating offset value to highest value
//if (i >= offSet)
//  offSet = i;

} catch (JSONException e) {
e.printStackTrace();
}

}

// notifying list adapter about data changes
// so that it renders the list view with updated data
mAdapter.notifyDataSetChanged();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();

}

}) {

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("User-agent", "My useragent");
return headers;
}
};

// Adding request to request queue
AppController.getInstance().addToRequestQueue(req);
hidePDialog();
}

appointmentlist_patient.php

<?php
$host = "localhost"; // host of MySQL server
$user = "root"; // MySQL user
$pwd = ""; // MySQL user's password
$db = "ecare"; // database name

// Create connection
$con = mysqli_connect($host, $user, $pwd, $db);

// Check connection
if(mysqli_connect_errno($con)) {
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$server_ip = gethostbyname(gethostname());

error_reporting(0);
// array for JSON response
$json = file_get_contents('php://input');
$response = array();
$data = json_decode($json);
$hi = $data->{'uid'};

$sql = "SELECT uid,appointment_type,doctor,date,time,queue from appointment Where uid = ".$hi;

$res = mysqli_query($con,$sql);

$result = array();

while($row = mysqli_fetch_array($res)){
array_push($result,array('uid'=>$row['uid']));
array_push($result,array('appointment_type'=>$row['appointment_type']));
array_push($result,array('doctor'=>$row['doctor']));
array_push($result,array('date'=>$row['date']));
array_push($result,array('time'=>$row['time']));
array_push($result,array('queue'=>$row['queue']));
}

echo json_encode($hi);

mysqli_close($con);

Я хочу передать параметры в php, но данные $ hi, которые я получил в php, равны NULL. Результат $ тоже пуст. Я проверял много раз, но я не знаю, в чем проблема. Пожалуйста, помогите мне решить эту проблему. Благодарю вас.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]