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
    }
  ]
}
2
  • 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? Commented Oct 1, 2019 at 4:14
  • I am trying stackoverflow.com/questions/49505372/… but in this case if i have subject section. not achieve right json. Commented Oct 1, 2019 at 4:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.