title: Break query data into several files
body: <p>I want to get table from database and then break output data by files (50 entries in each file): list01.txt, list02.txt... But somehow I got stacked at the question how to break data more effectively.</p>
  
  <pre><code>if ( $result = $mysqli-&gt;query($query) ) {
  
      icount = 0;
      while ( $row = mysqli_fetch_array($result) ) {
          if ( icount % 50 == 0 ) {
              $snum = int( icount / 50 );
              $filename = 'scripts/spisok'.$snum.'.txt';
              $handle = fopen( $filename, 'w' );
          }
          fwrite( $filename, $row['uname'].';'.$row['email'].'&lt;br /&gt;' );
          icount++;
      }
  
      echo 'ok';
      $result-&gt;free();
  
  }
  </code></pre>
  
  <p>Can I just break $result into 50-entry arrays first and then write them all? Sorry, im novice to PHP</p>