PHP & MySQL Table Report with a variable number of columns

Has anyone attempted or seen something like this before?

My PHP/MySQL knowledge is non-existent, though a friend assures me this would be pretty easy to do (although he has yet to make any suggestions about how to approach it…). The information I have is that this is a custom PHP build.

Read More

Also, I have searched a variety of help sites, however, without finding any examples of
code that could render a table from MySQL data that would allow the number of columns to fluxuate with the number of comma-delimited inputs in a field. So, here goes:

Using Gravity Forms v. 1.8.4, I have created a 40 item checkbox in field 4 of form 17, which appears on post 136 in WordPress 3.8.1. Users of the site are instructed to select exactly 7 of the 40 items. The selections are stored in the WordPress/MySQL table called, wp_rg_lead_detail, and are grouped by lead ID (which varies) and form ID (which is always 17).

In GF form 22, which appears on WP post 87:

  • first, users select from a dropdown menu (called field ID 2), the value “Shared Values Results” and,
  • then, in a single line text box (called field ID 3), users submit a series of common delimited numerals representing the user ID numbers of each user whose values will be compared in the resulting report. For example, a value of “1, 23, 95, 184” in field ID 3, form 22, should result in a report comparing the 7 items selected from field 4, form 17, for each of userID 1, userID 23, userID 95, and userID 184.

Now, I need to produce a report, which will appear on post 174. The layout should be a table, 41 rows by 3 or more columns, with the following parameters:

The first row will be a header containing the word “Values” in Row 1, Column 1, and the selected userIDs in each of Row 1, Columns 2, 3, etc. Rows 2-41 of Column 1 will be populated by each of the 40 items from checkbox at field 4, form 17. In Rows 2-41 of Columns 2, 3, etc., one “X” should appear in each cell that represents one of the 7 items selected by each user.

In our example, there would be 4 columns in addition to Column 1 (although the number of columns would vary depending on the number of user IDs provided for comparison). The result might look like this:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      Values   ''   1   ''   23   ''   95   ''  184   '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Collaboration  ''   X   ''        ''        ''   X    ' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Networking     ''       ''    X   ''        ''   X    ' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Independence   ''   X   ''        ''    X   ''   X    '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Security       ''       ''    X   ''        ''        '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Control        ''   X   ''    X   ''    X   ''   X    '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Compromise     ''   X   ''        ''    X   ''   X    '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Winning        ''   X   ''        ''        ''   X    '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
... etc., thru Row 41/Value # 40 ....

If you can point me to some code that I could adapt to this, I would really appreciate it. My searches to date may have been hampered by not knowing what terminology to use to attain this result.

Related posts

Leave a Reply