title: why php write empty lines into text file?
body: <p>I had a form which checkboxes that post selected rows to $_POST['select'][$i] array that used in select data from db.
  the result from sql is used to write the result into text file with newline but only write the first line and others are empty lines.
  please help.
  my code below.</p>
  
  <pre><code>&lt;?php 
  
      $rowCountd = count($_POST["select"]);
      for($i=0;$i&lt;$rowCountd;$i++) {
  
          $rowwd=$_POST['select'][$i]; 
  
          $path_stu_test = $_SERVER['USERPROFILE'].'\Documents\performance/student_test.txt';
  
          $file_stu_test = fopen($path_stu_test, 'w');    
  
          $stmt = $db-&gt;prepare('SELECT row_no, adms_no, full_name from stu_perform where row_no= :rowwd1');
  
          $stmt-&gt;bindParam(':rowwd1', $postrowwd1, SQLITE3_TEXT); $postrowwd1 = $rowwd;
          $ret = $stmt-&gt;execute(); 
  
          while($row = $ret-&gt;fetchArray(SQLITE3_ASSOC)){
  
              $adms_not = $row['adms_no'];
              $full_namet = $row['full_name'];
              $file2 = "$adms_not~$full_namet\r\n";
              fwrite($file_stu_test, $file2);
  
          }
      }
  ?&gt;
  </code></pre>
  
  <p>I think the problem is the way I used fwrite inside for() loop with While(){} block because the code below works i.e it display write all the sql result</p>
  
  <pre><code>&lt;?php
  
      $rowwd = 02;
      $path_stu_test = $_SERVER['USERPROFILE'].'\Documents\performance/student_test.txt';
  
      $file_stu_test = fopen($path_stu_test, 'w');
  
      $stmt = $db-&gt;prepare('SELECT row_no, adms_no, full_name from stu_perform where row_no= :rowwd1');
  
      $stmt-&gt;bindParam(':rowwd1', $postrowwd1, SQLITE3_TEXT);
      $postrowwd1 = $rowwd;
      $ret = $stmt-&gt;execute();
  
      while($row = $ret-&gt;fetchArray(SQLITE3_ASSOC)){
  
          $adms_not = $row['adms_no'];
          $full_namet = $row['full_name'];
  
          $file2 = "$adms_not~$full_namet\r\n";
          fwrite($file_stu_test, $file2);
  
      }
  ?&gt;
  </code></pre>