When creating a new table from an SQL query. I get the below error
There was an error while trying to save the table! OK
Notice: Undefined index: table in /var/www/html/dev/wp-content/plugins/wpdatatables/source/class.wpdatatable.php on line 1638
Notice: Trying to get property 'pos' of non-object in /var/www/html/dev/wp-content/plugins/wpdatatables/source/class.wdtconfigcontroller.php on line 780 {"table":{"_cacheHash":"","connection":null},"error":"Column 'pos' cannot be null"}
Tested the below SQL query in mysql and was able to generate results correctly.
SELECT IFNULL(grc,'NO GRC') AS grc, SUM(num_participants) as numparticipants, SUM(num_participants)/(SUM(SUM(num_participants)) OVER ())*100 AS pcparticipants, SUM(IFNULL(scj_completed,0)) AS scjcompleted, SUM(IFNULL(scj_not_completed,0)) AS scjnotcompleted FROM ( SELECT grc, COUNT(*) as num_participants, SUM(CASE WHEN scj_status = 7 OR scj_status = 8 THEN 1 ELSE 0 END) as scj_completed, SUM(CASE WHEN scj_status != 7 AND scj_status != 8 THEN 1 ELSE 0 END) as scj_not_completed FROM wp_scj_participants LEFT JOIN wp_scj_grcmap ON wp_scj_participants.postal_code = wp_scj_grcmap.postalcode WHERE scj_status IS NOT NULL AND (1=1 OR aip_date BETWEEN '%VAR1%' AND '%VAR2%')
GROUP BY wp_scj_grcmap.grc ) a GROUP BY grc ORDER BY num_participants DESC
grcnumparticipantspcparticipantsscjcompletedscjnotcompletedNO GRC6161.0000160JALAN BESAR1111.0000110DUMMY GRC88.000008MARINE PARADE77.000007EAST COAST55.000014ANG MO KIO22.000002ALJUNIED22.000002SEMBAWANG22.000020TANJONG PAGAR11.000001TAMPINES11.000001
You can try preparing a MySQL view (which will return the data that you need, call it e.g. “view1” and then build a wpDataTables based on a simple query like "SELECT * FROM view1″.
Do you know which part of the query I provided was causing the error? From what I see the functions I used are not blocked, as I have another query with SELECT, COUNT, SUM, IFNULL.
I can't say exactly what caused the issue, but it could be COUNT(*) or by using GROUP BY.
Please note some this when working with the server-side processing feature:
Please do not use “LIMIT” in the SELECT statement. wpDataTables adds it automatically and it will be overridden.
Please do not use “ORDER BY” in the SELECT statement. wpDataTables has its own sorting engine, so it makes no sense to use MySQL’s sorting, since it will be overridden. Also, server-side processing feature adds this part of the statement automatically when users trigger the sorting on the front-end, and having it in the initial statement may cause the table to crash.
When working with more complex queries, it's always better to create VIEWs in the database, and then pull them to create a table.
When creating a new table from an SQL query. I get the below error
There was an error while trying to save the table! OK
Notice: Undefined index: table in /var/www/html/dev/wp-content/plugins/wpdatatables/source/class.wpdatatable.php on line 1638
Notice: Trying to get property 'pos' of non-object in /var/www/html/dev/wp-content/plugins/wpdatatables/source/class.wdtconfigcontroller.php on line 780
{"table":{"_cacheHash":"","connection":null},"error":"Column 'pos' cannot be null"}
Tested the below SQL query in mysql and was able to generate results correctly.
SELECT
IFNULL(grc,'NO GRC') AS grc,
SUM(num_participants) as numparticipants,
SUM(num_participants)/(SUM(SUM(num_participants)) OVER ())*100 AS pcparticipants,
SUM(IFNULL(scj_completed,0)) AS scjcompleted,
SUM(IFNULL(scj_not_completed,0)) AS scjnotcompleted
FROM
(
SELECT
grc,
COUNT(*) as num_participants,
SUM(CASE WHEN scj_status = 7 OR scj_status = 8 THEN 1 ELSE 0 END) as scj_completed,
SUM(CASE WHEN scj_status != 7 AND scj_status != 8 THEN 1 ELSE 0 END) as scj_not_completed
FROM
wp_scj_participants
LEFT JOIN wp_scj_grcmap ON wp_scj_participants.postal_code = wp_scj_grcmap.postalcode
WHERE
scj_status IS NOT NULL
AND (1=1 OR aip_date BETWEEN '%VAR1%' AND '%VAR2%')
GROUP BY
wp_scj_grcmap.grc
) a
GROUP BY grc
ORDER BY num_participants DESC
grcnumparticipantspcparticipantsscjcompletedscjnotcompletedNO GRC6161.0000160JALAN BESAR1111.0000110DUMMY GRC88.000008MARINE PARADE77.000007EAST COAST55.000014ANG MO KIO22.000002ALJUNIED22.000002SEMBAWANG22.000020TANJONG PAGAR11.000001TAMPINES11.000001Hello Alvin
Our logic is based on a PHP SQL parser which has full support for the SQL dialect for the following statement types
SELECT, INSERT, UPDATE, DELETE, REPLACE, RENAME, SHOW, SET, DROP, CREATE INDEX, CREATE TABLE, EXPLAIN and DESCRIBE.
Some of them are disabled for security reasons.
You can try preparing a MySQL view (which will return the data that you need, call it e.g. “view1” and then build a wpDataTables based on a simple query like "SELECT * FROM view1″.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi Aleksandar,
Do you know which part of the query I provided was causing the error? From what I see the functions I used are not blocked, as I have another query with SELECT, COUNT, SUM, IFNULL.
I can't say exactly what caused the issue, but it could be COUNT(*) or by using GROUP BY.
Please note some this when working with the server-side processing feature:
When working with more complex queries, it's always better to create VIEWs in the database, and then pull them to create a table.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Noted on this, we'll try to put that in views if it becomes overly complex.
Thanks Alvin
If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables