0

I've been beating my head all day because of this. enter image description here

enter image description here

How to convert the results from the image above into json format like this

{
        "name": "João Batista Da Silva Júnior",
        "y": "9.83",
        "drilldown": "João Batista Da Silva Júnior",
        "data": [
            [
                "assiduidade",
                10
            ],
            [
                "normas",
                9
            ],
            [
                "eficiencia",
                10
            ],
            [
                "relacionamento",
                10
            ],
            [
                "iniciativa",
                10
            ],
            [
                "visao",
                10
            ]
        ]
    }
]

}

I'm trying this code but it doesn't reproduce the format required.

    $info["aval"] = array();
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        extract($row);
        $info2 = ['name' => $auxiliar, 'y' => $media, 'drilldown' => $auxiliar, 'data' => [[$topico, floatval($nota)]]];
        $info["aval"][] = $info2;
    }
kelsen
  • 29
  • 7
  • 1
    Possible duplicate of [JSON encode MySQL results](http://stackoverflow.com/questions/383631/json-encode-mysql-results) – castis Jul 19 '16 at 18:39
  • you're not going to be able to do that with a simple loop/array build. none of your `data` values appear by themselves in the table, and will have to be extracted, and some of those values don't appear AT ALL. – Marc B Jul 19 '16 at 18:39
  • Where does 9.83 come from, 'assiduidade', ...? None of these values relate to anything in the images. Also, don't post images. Copy the text into the question and format it as code. – trincot Jul 19 '16 at 18:41
  • The format is just an example of the structure, the `data` is actually the result from select on the second image. – kelsen Jul 19 '16 at 18:45
  • @MarcB can you point me at least the idea on how to achieve this? I'm lost here because I don't know how to handle those multiple rows from avaliacaoTopico table. – kelsen Jul 19 '16 at 20:24

0 Answers0