Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing fgetcsv and fopen issue with looping never exiting
    primarykey
    data
    text
    <p>There's an issue with this piece of code it never gets to the "Done" echo.</p> <pre><code> for($current_day=1;$current_day&lt;=10;$current_day++){ echo("lists/Day ".$current_day.".csv &lt;/br&gt;"); $person_data = ""; if ( ( $handle = fopen( "lists/Day ".$current_day.".csv", "r" ) ) !== FALSE ) { while ( ( $data = fgetcsv( $handle, 1000, ",", "//" ) ) !== FALSE ) { if ( $data[2]!="Grade" ) { $collection = $db-&gt;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-&gt;findOne(array('fullname'=&gt;$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] . "&lt;/br&gt;" ; $collection-&gt;save($cursor); } } else{ echo("ADD"); //addperson($data,$current_day); } } // do something with the data here //echo $data[0] . " - ". $data[1] . " - ". $data[2] . "&lt;/br&gt;" ; } fclose( $handle ); echo("Done"); } else{ echo "FALSE"; } } </code></pre> <p>outputs</p> <pre><code> 1 lists/Day 1.csv ADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADDADD </code></pre> <p>Which is correct but never loops to the second csv</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload