I have a csv file which have about 500000 number of rows. What I need to do is take first 100 rows in first loop and manipulate the rows (say, send first 100 IDs to API and save response). In Second loop, skip the first 100 rows(already taken) and take another 100 rows and send request to web service. Similarly, in third loop, skip first 200 rows and take another 100 rows and send request to web service and so on...
I can take single each rows with below code. (tested : works great)
if (($handle = fopen($filename, "r")) !== FALSE) {
$id = 1;
$line = fgetcsv($handle); //skip first row
//fetch data from each row
while (($data = fgetcsv($handle, ",")) !== FALSE) {
$hotel_id = $data[0];
//call service to request to web service
$hotelDetailRequest = (new \Services\Hotel\Hotel)->getHotelStaticData($hotel_id);
//do stuff to response
}
}
Similarly, I can skip some initial rows as like I skipped first row adding
$line = fgetcsv($handle);
$line = fgetcsv($handle);
$line = fgetcsv($handle);
But, this is not my expected result as explained above. I am using PHP(Laravel). I googled, but could not found any suitable that match my criteria. Has anyone face the same problem?
Any help would be appreciated. Thank You