I have a form with (including 'page' and 'fieldset') 15 field_names. When I try to query the db to display the data in a table, I recently started getting this error:
"Can\\'t use players: The SELECT would examine more than MAX_JOIN_SIZE
rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET
SQL_MAX_JOIN_SIZE=# if the SELECT is okay"
My query string (simplified to save space):
$querystr = " SELECT FN.sub_id, SEL.`sel`, FN.`First Name` , LN.`Last Name` , DOB.`dob` FROM ( SELECT sub_id, field_val AS 'First Name' FROM $wpdb->cformsdata WHERE `field_name` = 'First Name' )FN, ( SELECT sub_id, field_val AS 'Last Name' FROM $wpdb->cformsdata WHERE `field_name` = 'Last Name' )LN, ( SELECT sub_id, field_val AS `Team` FROM $wpdb->cformsdata WHERE `field_name` = 'Team' )TEAM, ( SELECT sub_id, field_val AS `dob` FROM $wpdb->cformsdata WHERE `field_name` = 'DOB' )DOB WHERE FN.sub_id = LN.sub_id AND LN.sub_id = TEAM.sub_id AND TEAM.sub_id = DOB.sub_id AND TEAM.Team = 'Boys' ORDER BY LN.`Last Name` ";
Can someone suggest a simpler approach to extracting the information for presentation on page?
WOW. This query certainly looks a bit over the top. Quite frankly I don't even understand what it is doing ;-)
I recommend you look at the cforms source code (cforms-database.php, js/include/lib_database_*) and extract the code you need to read all submissions/data and afterwards present it any way you want…
Basically, it makes a table of sub_id, and first name, a table of sub_id and last name, a table if sub_id and xxx…. then selects the values for all the sub_ids where field_name = "Team" and field_val = "Boys". Since I am not proficient at SQL, I'm sure there is a less expensive, more elegant way to do this.
Thanks for the pointers to the cforms source, that's where I was going to look next.
I see. Generally, I would rather do this kind of 'arranging of data' in an Array outside of SQL, unless the size of the data is so huge it would throw your PHP memory consumption over board. Then I would create something like 'views' within your SQL database tables that run in parallel to the cforms tables and essentially do what your SQL statements does, but on a server level.
i too have a similar problem, the cform tracking is and will only allow me to export so many records ie: only allow 60 days worth & not the entire ammount, ie: all year
so ive been trying to run this code localy on my 18mb wordpress database
using phpmyadmin, this piece of code was created from cb's snippet above.
FROM ( SELECT sub_id, field_val AS FirstName FROM wp_cformsdata WHERE field_name = "First Name" )FN, ( SELECT sub_id, field_val AS Surname FROM wp_cformsdata WHERE field_name = "Surname")SN, ( SELECT sub_id, field_val AS Height FROM wp_cformsdata WHERE field_name = "Height" )H, ( SELECT sub_id, field_val AS Age FROM wp_cformsdata WHERE field_name = "Age" )A, ( SELECT sub_id, field_val AS Postcode FROM wp_cformsdata WHERE field_name = "Postcode" )PC, ( SELECT sub_id, field_val AS City FROM wp_cformsdata WHERE field_name = "City" )CT, ( SELECT sub_id, field_val AS Address FROM wp_cformsdata WHERE field_name = "Address" )AD, ( SELECT sub_id, field_val AS Telephone FROM wp_cformsdata WHERE field_name = "Telephone" )TE, ( SELECT sub_id, field_val AS Email FROM wp_cformsdata WHERE field_name = "Email" )EM, ( SELECT sub_id, field_val AS Fieldset1 FROM wp_cformsdata WHERE field_name = "Fieldset1" )FS, ( SELECT sub_id, field_val AS page FROM wp_cformsdata WHERE field_name = "page" )PG, ( SELECT sub_id, field_val AS Attributes FROM wp_cformsdata WHERE field_name = "Main Attributes" )MA, ( SELECT sub_id, field_val AS Experience FROM wp_cformsdata WHERE field_name = "Playing Experience" )PE, ( SELECT sub_id, field_val AS School FROM wp_cformsdata WHERE field_name = "Current School/College/Employer" )CS, ( SELECT sub_id, field_val AS Position FROM wp_cformsdata WHERE field_name = "Player Position" )PN, ( SELECT sub_id, field_val AS Club FROM wp_cformsdata WHERE field_name = "Current Club" )CB, ( SELECT sub_id, field_val AS Weight FROM wp_cformsdata WHERE field_name = "Weight" )WT
WHERE FN.sub_id = SN.sub_id AND SN.sub_id = H.sub_id AND H.sub_id = A.sub_id AND A.sub_id = PC.sub_id AND PC.sub_id = CT.sub_id AND CT.sub_id = AD.sub_id AND AD.sub_id = TE.sub_id AND TE.sub_id = EM.sub_id AND EM.sub_id = FS.sub_id AND FS.sub_id = PG.sub_id AND PG.sub_id = MA.sub_id AND MA.sub_id = PE.sub_id AND PE.sub_id = CS.sub_id AND CS.sub_id = PN.sub_id AND CB.sub_id = WT.sub_id
ORDER BY SN.Surname LIMIT 60
There has to be an easier way in SQL to get the matchin records for each submission onto 1 recordset row,
??
any help guys would be great..
ps: Ive read through the source code for cforms many times and cant come to the conclusion on the query used to get the entire results which would then export as csv file…