• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

php to angular, keep array data

<button aria-describedby="--stacks-s-tooltip-2xwqlipo" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

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

enter image description here

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