Below is a sample table I've been working on,
table1
╔════╦══════════════╦═══════════╗════════════════════╗
║ id ║ file_id ║fieldname ║ from_column_number ║
╠════╬══════════════╬═══════════╣════════════════════╬
║ 1 ║ 5566533 ║ mid ║ 4 ║
║ 2 ║ 5566533 ║ old ║ 2 ║
║ 3 ║ 5566533 ║ fossil ║ 1 ║
║ 4 ║ 3232534 ║ old ║ 4 ║
║ 5 ║ 3232534 ║ mid ║ 3 ║
║ 6 ║ 3232534 ║ new ║ 2 ║
║ 7 ║ 3232534 ║ fossil ║ 1 ║
╚════╩══════════════╩═══════════╝════════════════════╝
I have CSV file's with their Id's in the column file_id ,their header names and their order as they appear in the files in column's fieldname and from_column_number respectively. ie,in the above case I've shown two file's with file_id 5566533 and 3232534.
They have their header order as
5566533:
fossil old mid
3232534:
fossil new mid old
I need to load the files into the below table,rearranging the way it loads for each file using the above information
For example,The file having the id 5566533 has the field mid in its fourth position in the above case.
table2
╔════╦══════════════╦═══════════╗════════════════════╗
║ id ║ mid ║old ║ fossil ║
╠════╬══════════════╬═══════════╣════════════════════╬
║ 1 ║ 422342343 ║ 12222 ║ 342342 ║
║ 2 ║ 234234 ║ 43234 ║ 3243 ║
║ 3 ║ 345435355445 ║ 234234 ║ 32432 ║
║ 4 ║ 3455544534 ║ 2343245 ║ 4234 ║
║ 5 ║ 345345544454 ║ 432234 ║ 324545 ║
║ 6 ║ 554345345 ║ 34243 ║ 453242 ║
║ 7 ║ 77w345544533 ║ 34234455 ║ 5245345 ║
╚════╩══════════════╩═══════════╝════════════════════╝
I can use only plain SQL and a bit of PHP for this purpose.g
345345544454numbers? Is thewa typo? What did you tried so far?