Create Datatable from SQL query.

Create Datatable from SQL query.

MickBMickB Posts: 103Questions: 25Answers: 2

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

Answers

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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() or data.

    Allan

  • MickBMickB Posts: 103Questions: 25Answers: 2

    I just get the array_keys of my result, then pass that as a separate array to my template, which the Datatable can use.

This discussion has been closed.