I'm pulling records from a database which i'm able to display the data in JSON format the way i want and it works perfectly. The problem here its there's a token i generate on the page which i want to add to the payload that the user gets and this's what i'm getting
{"user_details":[{
"id":"1",
"fname":"xxx",
"lname":"xxx Mensah",
"phone_number":"0000000",
"email":"[email protected]",
"username":"xx",
"password":"xx",
"user_type":"xx"
}],
"token":"xxxxx"}
but i want to get the results like this
[{"user_details":{
"id":"1",
"fname":"xxx",
"lname":"xxx Mensah",
"phone_number":"0000000",
"email":"[email protected]",
"username":"xx",
"password":"xx",
"user_type":"xx"
},
"token":{"xxxxx"}
]
PHP
$token = xxxxx
$row = $conn->query("SELECT * from users where username='".$username."' and password='".$password."'");
$row->setFetchMode(PDO::FETCH_ASSOC);
$userdetails = $row->fetchAll(PDO::FETCH_OBJ);
$results = array(
'user_details' => $userdetails,
'token' => $token
);
echo json_encode(($results));
MYSQLI_orPDOAPI's