I´m having this issue, I did the mysql query inside a class and then wanted to extract the sequence in a JSON format (up to this everything ok), then tried to decode the JSON to put inside different variables the fields needed, but it keeps showing me just the array secuence, example:
public function Users() {
$array = array();
//$connection to db;
$sql = mysql_query("SELECT * FROM users WHERE id='".$variable."'");
$data = mysql_fetch_array($sql);
$users = array(
'id'=>$data['id'],
'username'=>$data['username'],
'name'=>$data['name'],
'lastname'=>$data['lastname']
);
$user = json_encode($users);
echo $user;
}
Then in a another page I tried to deode the secuence like this:
include"class.php";
$user = new Query();
$usr = json_decode($user->User());
echo $usr->id;
but my result is:
{"id":"1","username":"someone","name":"Name","lastname":"Last"}
why, is the class causing the conflict?, how can I use a simpleclass to use it whenever I want to later on the run?
Thanks,
You are echoing
$userin yourUsers()function. You need to return it instead.return $user;