bennybutler
asked on
fgetcsv loop returns 1 row to many
I have been using this loop that I pulled from the php.net website:
do (($data = fgetcsv($csv, filesize("./trial_imports/ ".$file), ",")) !== FALSE) {
//perform actions
}
But each time it runs, it always runs through one row too many, inserting a blank row into the database.
I tried making it a do/while but got the same results.
I would change it to loop through based on a count I keep up with, but I don't see a countrows function for the csv file. I've been up working on this for a long time, so I'm probably missing something simple. Maybe someone can think about it while I sleep ;)
do (($data = fgetcsv($csv, filesize("./trial_imports/
//perform actions
}
But each time it runs, it always runs through one row too many, inserting a blank row into the database.
I tried making it a do/while but got the same results.
I would change it to loop through based on a count I keep up with, but I don't see a countrows function for the csv file. I've been up working on this for a long time, so I'm probably missing something simple. Maybe someone can think about it while I sleep ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
while($data = fgetcsv($csv, filesize("./trial_imports/
//perform actions
}
because the manual says fgetscsv returns false on error or EOF so maybe the !== FALSE doesnt match up with the EOF mark properly?