Use PHP to create SQL Query, then pass to DataTables
Use PHP to create SQL Query, then pass to DataTables
aallard
Posts: 2Questions: 2Answers: 0
I have an existing PHP class that performs a very complex query (joining over 8 tables). I would like to use the resultset from this query and send it to DataTables. Is there an easy way for me use my existing php?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The example below is a little bit of my DataTables server-side code that I will share. I also have to use very complicated queries, and make well over 20 tables that are all very different so something like this was very much needed. You can simply build the SQL as a string then send it to the DataTables class. Then you can make your super query into a subquery so it still works with all the DataTables magic (letting sorting, searches, etc work). Be sure in your filter function you protect yourself against SQL injection.
I also built a dynamic function passing method to change formats of dates, numbers, create URLs, insert images, buttons, etc since I find it much easier doing all my data modification on the server-side as well. Use their class file, and this as an example and build your own class file to work however you need it to. The only requirement is by the end of it you return the correct data format for the DataTables front end.
Looks like a good solution, but I don't understand how you use $model (create it etc) and it seems to me that you also modified the order, limit and filter functions inside the SSP class.
Could you please give a more detailed example?
I submitted a more complete example to github here