I'm trying to do a query that is joining two tables. This join is for a CSV output and requires the values of one table to be the column headings of the CSV with the actual value as values showing 1 or 0.
I can do this by looping through the first table with PHP and doing queries with each iteration of the loop.. but that will be way too hard on the server since we're talking thousands of records. I'm hoping it would be possible with a single query.
As an example, we have two tables. tblSchedule and tblResults
tblSchedule has the following columns..
SID (unique)
NameVal (name of the speaker varchar(250))
tblResults has the following columns..
RID (unique)
SID (foreign key)
FirstName (name of participant varchar(250)))
LastName (name of participant varchar(250)))
Before, all I needed to provide for a CSV output was tblResults and joining tblSchedule.. So participant and speaker name were output.
NOW.. which sucks, is that the want a CSV output with column names for EVERY speaker. The records are items in tblResults, and if that particular participant is seeing that speaker in tblSchedule, to show a 1 in that column, else shows 0.
I have 160 entries in tblSchedule, so that would be 160 columns, and I have about 14,000 entries in tblResults.
I maybe overthinking this a bit.
So the CSV would look something like this...
FirstName, LastName, Speaker1, Speaker2, Speaker3,..... Speaker160
Joe, Schmoe, 0, 0, 1,.....0