I'm trying to create a php page that should shows me a json output.. I'm in a wordpress website and maybe it's a little bit different to retrive datas from database than in a normal php page. By the way, this is my code:
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
global $wpdb;
$code = '';
$code=$_REQUEST['code'];
$timestamp = '';
$timestamp=$_REQUEST['timestamp'];
$username = '';
$username=$_REQUEST['username'];
$selectData = "SELECT * FROM protocol_data_list WHERE username = '$current_user->user_login'";
//Create an array
$json_response = array();
$result = $wpdb->query($selectData);
echo $result;
while ($row=mysqli_fetch_array($result, MYSQL_ASSOC)) {
echo $row;
$row_array['code'] = $row['code'];
$row_array['timestamp'] = $row['timestamp'];
$row_array['username'] = $row['username'];
array_push($json_response,$row_array);
}
$json_response = str_replace('\\/', '/', json_encode(array('item' => $json_response), 128));
echo $json_response;
?>
this kind of code is the one i use always to create a json.. But in wordpress it returns an empty array.. I don't know if something's wrong.