My query works in phpmyadmin but gives me an error when I use the exact same query in the data tables. The error comes when I try to left join a table on a subquery using substring_index function. It gives me the "cannot calculate position of..." error.
Query:
SELECT d.campaign_id, d.amount, cd.first_name, cd.last_name, cd.email, p.post_date AS date, ifnull(u.display_name, 'anonymous') as athlete, u.ID as athlete_id
FROM `wp_charitable_campaign_donations` AS d
LEFT JOIN `wp_charitable_donors` AS cd on cd.donor_id = d.donor_id
LEFT JOIN `wp_posts` AS p on p.ID = d.donation_id
LEFT JOIN `wp_postmeta` AS pm on pm.post_id = d.donation_id
If your MySQL-query based wpDataTable doesn’t work correctly with server-side processing, probably this is happening because wpDataTables server has problems with parsing of the query and building new queries dynamically (happens rarely, but does sometimes). To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.
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 statement automatically when users triggers the sorting on the front-end, and having it in initial statement may cause the table to crash.
My query works in phpmyadmin but gives me an error when I use the exact same query in the data tables. The error comes when I try to left join a table on a subquery using substring_index function. It gives me the "cannot calculate position of..." error.
Query:
SELECT d.campaign_id, d.amount, cd.first_name, cd.last_name, cd.email, p.post_date AS date, ifnull(u.display_name, 'anonymous') as athlete, u.ID as athlete_id
FROM `wp_charitable_campaign_donations` AS d
LEFT JOIN `wp_charitable_donors` AS cd on cd.donor_id = d.donor_id
LEFT JOIN `wp_posts` AS p on p.ID = d.donation_id
LEFT JOIN `wp_postmeta` AS pm on pm.post_id = d.donation_id
LEFT JOIN `wp_users` AS u on u.ID =
(
SELECT substring_index(substring_index(pm.meta_value, '%_%', -2), '%_%', 1)
)
WHERE pm.meta_key = 'donor' AND
d.campaign_id = 1834 AND
p.post_status = "charitable-completed"
GROUP BY d.campaign_donation_id
HI hernahi,
Thank you for your purchase.
If your MySQL-query based wpDataTable doesn’t work correctly with server-side processing, probably this is happening because wpDataTables server has problems with parsing of the query and building new queries dynamically (happens rarely, but does sometimes). To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.
Please note some this when working with the server-side processing feature:
Best regards.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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
Hello Bogdan,
Thanks for the response. Will I still be able to use placeholders when using views?
Hi hernahi,
You can use the placeholders but not in the VIEW.
You can create some VIEW for example view_one and then use the placeholders so the query should look like this for example
SELECT * FROM view_one
WHERE (someplaceholder like) %CURRENT_USER_ID% = 3
Best regards.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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 Bogdan,
That worked perfectly. Thank you!
Hi hernahi,
You are welcome.
Hope that everything will work fine now.
Best regards.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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