SQL Query Help
-
Hi Michael,
I hope you are well?
You seem to have missed my query regarding making the export features of the plugin secure, so I decided to make an API myself!
I’ve created an SQL query of the form submissions and am hoping to make a JSON output as a result. I was wondering if you could help as I’m using your SQL example query as a basis.
I just started structuring a table of results using this SQL Query which is based on your website:
SELECT DATE_FORMAT(FROM_UNIXTIME(submit_time), ‘%b %e, %Y %l:%i %p’) AS Submitted, MAX(IF(field_name=’Username’, field_value, NULL )) AS ‘Username’, MAX(IF(field_name=’Value’, field_value, NULL )) AS ‘Value’, MAX(IF(field_name=’Ticket’, field_value, NULL )) AS ‘Ticket’, MAX(IF(field_name=’Renewal’, field_value, NULL )) AS ‘Renewal’ FROM wp_cf7dbplugin_submits WHERE form_name = ‘Order Status Report’ GROUP BY submit_time ORDER BY submit_time DESC
I now want to add a string to this so it filters by Username so I can effectively run this as a unique table of results for a specific user and build the JSON output. I have a customer with the Username ‘CHEESE’, so I tried the following:
SELECT DATE_FORMAT(FROM_UNIXTIME(submit_time), ‘%b %e, %Y %l:%i %p’) AS Submitted, MAX(IF(field_name=’Username’, field_value, NULL )) AS ‘Username’, MAX(IF(field_name=’Value’, field_value, NULL )) AS ‘Value’, MAX(IF(field_name=’Ticket’, field_value, NULL )) AS ‘Ticket’, MAX(IF(field_name=’Renewal’, field_value, NULL )) AS ‘Renewal’ FROM wp_cf7dbplugin_submits WHERE form_name = ‘Order Status Report’ AND field_value = ‘CHEESE’ GROUP BY submit_time ORDER BY submit_time DESC
It does correctly filter the results and shows only the orders for CHEESE, only now the Value, Ticket and Renewal columns all contain ‘NULL’, so no data is showing for the order.
Any thoughts on what I could be doing wrong?
Many thanks,
S
The topic ‘SQL Query Help’ is closed to new replies.