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
}
]
}