I have my php
code which save my db data into array. Then I use json_encode
to send it to angular.
In Angular, I am using httpClient
with the get method the get my data. But I got the data in many objects
instead of array
as I format it in my php
code.
I have tried to use JSON.parse
in angular with my responseData
but I got error. I'd like to keep my array
or array
(from php
) since I need to use *ngFor
in angular
which works only with array.
phpcode :
$q=mysqli_query($mysqli, "SELECT user_id FROM USER WHERE type='joueur'
");
while ($row=mysqli_fetch_object($q)){
$result[]=$row;
}
foreach($result as $key => $re) {
$id = $re -> user_id;
$get_matinal = mysqli_query($mysqli, "SELECT MATINAL.*, USER.nom, USER.prenom FROM MATINAL
INNER JOIN USER
ON USER.user_id = MATINAL.user_id
WHERE USER.user_id = $id
");
$while_index = 0;
while($row=mysqli_fetch_object($get_matinal)) {
$get_matinal_resultat[$id]['DataSet']['data'][$while_index] = $row -> moyenne_fatigue;
$get_matinal_resultat[$id]['DataSet']['label'] = 'indice';
$get_matinal_resultat[$id]['Label'][$while_index] = $row -> created_at;
$while_index = $while_index + 1;
}
}
echo json_encode($get_matinal_resultat);
echo mysqli_error($mysqli);
angular code :
this.http.get(this.server + 'getMatinal.php').subscribe(resData => {
this.full_graph = resData;
console.log(this.full_graph);
})
Here is the console log
So I got object of object whereas in php I did array of array. I'd like to keep the "attribute" since it's a "indexed array", but then I need to have some arrays and not objects..
Hope I have explained it correctly.
UPDATE :
Here is what I'd like to get as a result :
this.full_graph =
[
{
user_id : '9',
dataset: [{data:[2,4,3,3,5], label:'indice'}],
label: ['1','2','3','4','5']
},
{
user_id : '15',
dataset: [{data:[2,4,3,3,5], label:'indice'}],
label: ['1','2','3','4','5']
},
]
Thanks