iceblox Posted August 5, 2009 Share Posted August 5, 2009 Hi Guys, Im really stuck i have been looking around and just cant seem to find the answers i need to help me with my project. I want to use fgetcsv to get my csv file and i want to be able to run my scripts in segments i.e run 1000 lines then redirect the file back round carrying a start variable in the url. Hope this is clear? Does any one have any ideas on how i can get this to work? This doesnt work but have this so far.. <?php $fh = fopen("contacts.csv", "r"); fgetcsv ($fh, 10000); for ($row = 0; $line_array = fgetcsv ($fh, 10000); ++$row) { echo ""; } ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/168987-fgetcsv-and-for-loops/ Share on other sites More sharing options...
taquitosensei Posted August 5, 2009 Share Posted August 5, 2009 There's probably better ways but this should would work $counter=0; $handle = fopen("contacts.csv", "r"); while(($data=fgetcsv($handle,1000,",")) !== FALSE) { if($counter < 1000) { } $counter++; } Link to comment https://forums.phpfreaks.com/topic/168987-fgetcsv-and-for-loops/#findComment-891605 Share on other sites More sharing options...
iceblox Posted August 5, 2009 Author Share Posted August 5, 2009 Thanks for the input! I gave that a try and it does sort of work however if i set counter to 500 as i want it to start there it always prints row 1 but i dont want it to start until row 500? i thought id need to do something like for ( $counter = 5; $counter <= 300; $counter += 10) { but cannot get it to work Link to comment https://forums.phpfreaks.com/topic/168987-fgetcsv-and-for-loops/#findComment-891609 Share on other sites More sharing options...
iceblox Posted August 5, 2009 Author Share Posted August 5, 2009 Any ideas on this? I thought there was a variable i could pass in fgetcsv to tell it what line number to start at? Really stuck, any help would be appreciated. Phil Link to comment https://forums.phpfreaks.com/topic/168987-fgetcsv-and-for-loops/#findComment-891664 Share on other sites More sharing options...
iceblox Posted August 6, 2009 Author Share Posted August 6, 2009 Anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/168987-fgetcsv-and-for-loops/#findComment-891992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.