0

I am a new student in PHP PDO. and I want to create a student report card. I want to fetch data from mySql. and showing into a table. but there are some issue for creating a JSON from mySql data. because i was not able to bifurcate in nested JSON data. I am getting data from mySql. like below table.

|----------|------------|---------|---------|-----------|----------|--------------|
| class_id | student_id | exam_id |  sub_id | sub_lavel | max_mark | marks_obtain |
|----------|------------|---------|---------|-----------|----------|--------------|
|    5     |     101    |    11   |    51   |     1     |    100   |      85      |
|    5     |     101    |    11   |    52   |     1     |    100   |      78      |
|    5     |     101    |    11   |    53   |     1     |    100   |      65      |
|    5     |     101    |    12   |    51   |     1     |     50   |      45      |
|    5     |     101    |    12   |    52   |     1     |     50   |      35      |
|    5     |     101    |    12   |    53   |     1     |     50   |      49      |
|----------|------------|---------|---------|-----------|----------|--------------|

how to create a nested json like

{
  "class_id": 5,
  "student": [
    {
      "student_id": 101,
      "exam": [
        {
          "exam_id": 11,
          "subject": [
            {
              "sub_id": 51,
              "marks_obtain": 85,
              "max_mark": 100
            },
            {
              ...nextsubject
            }
          ]
        },
        {
          ...nextexam
        }
      ]
    },
    {
      ...nextstudent
    }
  ]
}
user1727852
  • 123
  • 2
  • 10
  • What have you tried? what is "some issues" that you have? can you show us what is your attempt to solve your problem and what is the expected json? – catcon Oct 01 '19 at 04:14
  • I am trying https://stackoverflow.com/questions/49505372/creating-nested-json-using-php-mysql but in this case if i have subject section. not achieve right json. – user1727852 Oct 01 '19 at 04:19

0 Answers0