Creation of files to record bank data

1

I have 13640 users and I'm creating 1 email capture file for every 1000 users. With the code I have, it generates 13 files and has a surplus of 640 users that are left behind because it did not reach counter 1000. So 13 files remain instead of 14, the last one that is not created would not store 1000, plus the rest (640).

The code I'm using to create the files inside the folder is this:

// Instrução até chegar na quantidade final de registros
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

    $contador++;

    if($contador == 1000){

        $excel      = new ExcelWriter("listas/report".rand(10000, 99999).".xls");

        $contador = 0;

    }

}

The variable $ excel takes care of a class to create these files each time the loop happens but does not create the last file because it does not reach 1000 registers but 640. How could you edit this code to get the desired result? / p>     

asked by anonymous 15.05.2014 / 15:23

1 answer

4
$contador = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   if( $contador++ % 1000 == 0 ) { // assim teremos um ExcelWriter no 1o item de cada 1000.
      $excel = new ExcelWriter("listas/report".rand(10000, 99999).".xls");
   }
   echo $row['email']; // troque pro campo correto da base de dados, apenas para teste
   $excel... // ponha aqui o método que escreve a linha no Excelwriter criado
             // pois essa parte do loop é executada para cada um dos itens, incluindo
             // os 640 finais.
}

This is just an outline, I do not know the details of ExcelWriter, but I think it works out.

    
15.05.2014 / 16:10