php - Using fgetcsv and fopen issue with looping never exiting -
there's issue piece of code never gets "done" echo.
for($current_day=1;$current_day<=10;$current_day++){ echo("lists/day ".$current_day.".csv </br>"); $person_data = ""; if ( ( $handle = fopen( "lists/day ".$current_day.".csv", "r" ) ) !== false ) { while ( ( $data = fgetcsv( $handle, 1000, ",", "//" ) ) !== false ) { if ( $data[2]!="grade" ) { $collection = $db->students; $person_data['last_name'] = trim( $data[0] ); $person_data['first_name'] = trim( $data[1] ); $person_data['fullname'] = $person_data['first_name'].' '.$person_data['last_name']; //var_dump($person_data); $cursor = $collection->findone(array('fullname'=>$person_data['first_name'].' '.$person_data['last_name'])); if($cursor!=null){ echo("update"); if($cursor['frees'][$current_day-1] != 1){ $cursor['frees'][$current_day-1] = 1; echo 'updated: '.$data[0] . " - ". $data[1] . " - ". $data[2] . "</br>" ; $collection->save($cursor); } } else{ echo("add"); //addperson($data,$current_day); } } // data here //echo $data[0] . " - ". $data[1] . " - ". $data[2] . "</br>" ; } fclose( $handle ); echo("done"); } else{ echo "false"; } }
outputs
1 lists/day 1.csv addaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadd
which correct never loops second csv