Link to home
Start Free TrialLog in
Avatar of Cenobitez
Cenobitez

asked on

Breaking 2 CSVs containing some identical data and insert into mysql database.

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[1] && array_file1[2] with array_file2[3] && array_file2[3] 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[1], array_file2[1], array_file2[2], array_file1[3], array_file1[4] \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 ?


ASKER CERTIFIED SOLUTION
Avatar of Barthax
Barthax
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial