这段代码有一个问题,它永远不会到达“完成”回声。
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);
}
}
// do something with the data here
//echo $data[0] . " - ". $data[1] . " - ". $data[2] . "</br>" ;
}
fclose( $handle );
echo("Done");
}
else{
echo "FALSE";
}
}
输出
1
lists/Day 1.csv
ADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADD
这是正确的,但永远不会循环到第二个 csv