I have 3 tables. Apls, Hulls and AplsHulls.
Apls consists of id, name, date Hulls consists of id, production_name AplsHulls is a join table and consists of id, apl_id, hull_id, status.
Not every Hull is associated with each Apl. The ones that are are in the join table with a status (shipped,in production, etc.)
I need to display a report in a table/grid that has the following columns headers: Apl Name, Apl_Date then the hull production names as the remaining column titles. (if hull 7 isn't in the result set, it doesn't even get a column.
For the data I need to list the apl name, apl date, then loop across the remaining columns and fill in the status for the records in the join table. If the apl and hull aren't associated in the join table, then just fill the cell with "NA".
I have tried this a bunch of different ways and I can currently get the dynamic list of column headers for the hulls, I never seem to be able to get the data to loop across correctly.
Sample Data:
Apls Table
Id: 1, Name: X1-0000, Date: 1/1/2009
Id: 2, Name: BG-5480, Date: 2/22/2009
Id: 3, Name: HG-0000, Date: 2/27/2009
Hulls Table
Id: 1, Production_name: ProdA
Id: 2, Production_name: ProdB
Id: 3, Production_name: ProdC
Id: 4, Production_name: ProdD
AplsHulls Table
Id: 1, Apl_id: 1, Hull_id: 1, Status:Delivered
Id: 2, Apl_id: 1, Hull_id: 3, Status:Ordered
Id: 3, Apl_id: 2, Hull_id: 4, Status:Delivered
I need the table to show like this:
APL | Date | ProdA | ProdC | ProdD
X1-0000 | 01/01/2009 | Delivered | Ordered | NA
BG-5480 | 02/22/2009 | NA | NA | Delivered
Notice the column headers ignore ProdB since that record wasn't in the join table at all. Also it fills in NA for the columns that are in the join table but it may not have an association to in the join table.
It is very confusing, I know.