I am playing around MySQL and got stuck.
I have an item Table and a table with attributes and values.
SELECT i.name, ia.name, iav.value FROM `item_attrib_values` iav
JOIN item_atributs ia ON iav.ia_ID = ia.ID
JOIN items i ON iav.i_ID = i.ID
JOIN item_class ic ON ic.ID = i.ic_ID
WHERE ic.ID = 1
This is my Query and it works fine.
The Result in MySQL looks like this:
Item Attrib Value
Rohr 1 diameter 16
Rohr 1 Fluid Code FW
Rohr 1 From 3
Rohr 1 To 2
Rohr 1 Subcontractor 1
Rohr 1 Paint A3
Rohr 1 Insulation HS
Rohr 2 diameter 80
Rohr 2 Fluid Code FW
Rohr 2 From 1
Rohr 2 To 3
Rohr 2 Subcontractor 1
Rohr 2 Paint A3
Rohr 2 Insulation HS
My problem is now, how do I get this into a Table that looks like this:
item diameter Fluid Code From To Subcontr. Paint Insulation
Rohr1 16 FW 3 2 1 A3 HS
Rohr2 80 FW 1 3 1 A3 HS
My first Idea was to QUery all Attributes first to build the Table head. -> Works fine but how do I assign the values to the corresponding tableheads. Especialy if 1 Item does not have one of the attribs set?
My second Idea was, if it is possible to build the Table out of one Query because all data are already in the array.
But I haven't figured out how to sort this
Array ( [0] => Array ( [Item] => Rohr 1 [attrib] => diameter [Value] => 16 ) [1] => Array ( [Item] => Rohr 1 [attrib] => Fluid Code [Value] => FW ) [2] => Array ( [Item] => Rohr 1 [attrib] => From [Value] => 3 ) [3] => Array ( [Item] => Rohr 1 [attrib] => To [Value] => 2 ) [4] => Array ( [Item] => Rohr 1 [attrib] => Subcontractor [Value] => 1 ) [5] => Array ( [Item] => Rohr 1 [attrib] => Paint [Value] => A3 ) [6] => Array ( [Item] => Rohr 1 [attrib] => Insulation [Value] => HS ) [7] => Array ( [Item] => Rohr 2 [attrib] => diameter [Value] => 80 ) [8] => Array ( [Item] => Rohr 2 [attrib] => Fluid Code [Value] => FW ) [9] => Array ( [Item] => Rohr 2 [attrib] => From [Value] => 1 ) [10] => Array ( [Item] => Rohr 2 [attrib] => To [Value] => 3 ) [11] => Array ( [Item] => Rohr 2 [attrib] => Subcontractor [Value] => 1 ) [12] => Array ( [Item] => Rohr 2 [attrib] => Paint [Value] => A3 ) [13] => Array ( [Item] => Rohr 2 [attrib] => Insulation [Value] => HS ) )
Into the Table I want.