Create Datatable from SQL query.
Create Datatable from SQL query.
Hi,
Is there a simple way to create a Datatable from an SQL SELECT statement (or an array of rows)?
I don't want to have to define the columns. This is just for a quick report viewer, where is pulls a SELECT from a reporting table, then runs the report.
This doesn't need to be editable.
Mick
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You need to define the columns in DataTables - there is no way around that I'm afraid. However, you could perhaps use a simply query to get the columns of the table and build a table based on that.
Aside from that, then yes, if you have an array of rows, simply use
rows.add()
ordata
.Allan
I just get the array_keys of my result, then pass that as a separate array to my template, which the Datatable can use.