Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fromthedark_14's avatar

Database tables values assign as a table header in the dataTables

How can I make table values from database to be my table header in my dataTables?

So here's the thing, supposedly I have this database:

ID      studenID        student_name        subject     grades
-----------------------------------------------------------------------------------------
1       1               student1            Math        90                          
2       1               student2            English     90
3       1               student3            Science     96
4       2               student1            Math        92                          
5       2               student2            English     93
6       2               student3            Science     95

And my datatables, what I am imagining is something like this:

ID      student_name        Math        English     Science
------------------------------------------------------------------------------------
1           student1        90          90          96                          
2           student2        92          93          95
0 likes
7 replies
Robstar's avatar

What on earth do you mean by "my dataTables". We're not clairvoyant.

fromthedark_14's avatar

Hi @Robstar :) sorry about that. What I want is to display something like this :

ID      student_name        Math        English     Science
------------------------------------------------------------------------------------
1           student1                90              90                  96                          
2           student2            92          93              95
Vilfago's avatar
Vilfago
Best Answer
Level 20

Is the subject constant or not ? If yes, just put them in your code.

If you have to retrieve them, you can use a groupby subject and foreach the result.

shez1983's avatar

i think he meant if the headers change or stay the same...

Please or to participate in this conversation.