Breaking 2 CSVs containing some identical data and insert into mysql database.
Posted on 2006-04-22
My PHP is a little broken at the moment, i'm still learning and not having much luck with this problem.
I have 2 files both CSV files containing data.
One contains data in this format
PLU1, Cola ,53, 25
The other one contains data in this format
Pepsi, Cola, PLU1
I want to end up with
PLU, Pepsi, Cola, 53, 25
I was thinking (Pseudo Code)
Load each line into an array of file 1
Load each line into an array of file 2
Compare array_file1 && array_file1 with array_file2 && array_file2 if they match, write the SQL Query to file, when complete write the file to data.sql ready to load into SQL when required.
I assume i would just write "array_file1, array_file2, array_file2, array_file1, array_file1 \n" to the file.
The problem i am having is looping the data to check ALL the files against ALL the others, and then Any that dont match having them put out separately, so i end up with 5 part CSV and 2 left overs files, of data that didnt match.
I must apologise that i dont have kind of working code, as i have no idea how to start this.
Any idea's ?