Good night,
I'm trying to pass an array to json but it only passes the last variable
function GetSuppliersView() {
global $db;
global $id;
global $type;
try{
$query = $db->query("SELECT * FROM suppliers WHERE id = $id");
$row=$query->fetch(PDO::FETCH_ASSOC);
$result['success'] = true;
$result['result'] = $row;
$querytwo = $db->query("SELECT name FROM third_party_services LEFT JOIN suppliers_services ON third_party_services.id = suppliers_services.id WHERE supplier_id=$id");
$x=0;
while($services = $querytwo->fetch(PDO::FETCH_ASSOC)) {
$var[$x] = $services['name'];
}
$result['secondresult'] = array_values($var);
echo json_encode($result);
return true;
} catch (PDOException $pe) {
return false;
}
}
The variable $ result ['result'] goes well, but $ result ['secondresult'] only passes the last item to be assigned