Is it possible to enter a php function instead of a table field?
Is it possible to enter a php function instead of a table field?
Maybe is a silly question but I could not find an example.
In a table I need to add a column that is resulted from an sql query, a simple count. I solved this by calling a php from javascript on render. Of course, this created the problem with multiple request on server due to the way Datatables is build. I solved this by caching the requests in a local array so this reduced the number of ajax calls to the number of rows but is there a better way then this work-around?
Can I return the result of the query directly from server-side php that initiate the DataTable and the Editor?
This question has accepted answers - jump to:
Answers
Use a one-to-many join and use the
length
property of the array. That should be significantly more efficient.The other option would be to create a VIEW with the required data.
Allan
VIEW - good idea. Will test it.
Mjoin - let me make sure I understood correctly. What I need to compute is a simple order count in this case. Link between company and orders are in another one-to-many table, as usual.
So I should try to create an Mjoin and render the lenght of the array?
I'm new to datatables so maybe I ask silly questions. Sorry if it is the case.
With the Mjoin - the actual data from the join would be redundant, but what you are really interested in is the number of entries. So you are moving the "count" action from the server-side to the client-side. Its not as efficient as it could be to get just the count, but it is vastly more so that sending an Ajax request for each cell.
Allan