I have a MySQL table named "relations", as follows:
from to count
-------------
A B 456
A C 233
A D 463
B A 766
B C 215
B D 142
(In reality, "from" and "to" contain names of people and the table contains 150 rows). I now need to export this table to an excel file (not CSV) in (150x150) matrix form, like this:
| A B C D
--+------------------
A | 0 456 233 463
B | 766 0 215 142
I need to do this from within PHP, but don't know how to go about this. Do I first create an empty Excel file, naming all the rows and columns? (so like this:)
| A B C D
--+------------------
A |
B |
If I do this, then how can I connect to the right cell to insert the correct counts? Or do I write the Excel file from within PHP alltogether?
Also, in reality the table is not structured, so it looks something like:
from to
-------
A C
F K
F L
B Z
M P
P A
So I don't think I'm able to write cell-by-cell, row-for-row. Or I should first query the database to sort by column "from" and then by column "to", probably.
Any help to get me started would be greatly appreciated.