Forum Moderators: coopster

Message Too Old, No Replies

Importing to MySQL with fgetcsv()

         

bumpaw

10:14 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



I have been using a PHP4 script to import a .csv feed that is too big for Excel now. I used to download and clean it up. The problem is that it has duplicate rows which need to be eliminated so that the database will only contain unique SKUs. Is there a query to use or a php function that will eliminate the duplicates and keep the script from stopping when it hits the first duplicate?

jatar_k

10:15 pm on Sep 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do a select for the SKU before the insert

if it already exists, continue

bumpaw

3:37 am on Sep 23, 2006 (gmt 0)

10+ Year Member



Could you give me a quick example? I see where you are going and found lots of references, but I after a couple of hours trying I don't have it.

jatar_k

5:01 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



use fgetcsv in a loop I'm guessing

first line would extract values and get the SKU which I am guessing is your key or is at least unique

then use that SKU to select from your db

if it returns a row then continue

else insert the row