title: PHPExcel multiple foreach loops
body: <p>I want to display all the rows from a table with the corresponding column names above, which works. The problem is that it removes the first row from the results below the column names. It's as if the column row is somehow counted as a row in the while loop that displays the results, but I can't figure it out.</p>
  
  <p>If I remove the column names code shown below all of the results are shown.</p>
  
  <pre><code>//COLUMN NAMES
  foreach($headings as $heading) { 
  
      $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($col.$rowNumber,$heading); 
      $col++;
  
  }
  </code></pre>
  
  <p>All of the code shown below.</p>
  
  <pre><code>$query = "SELECT * FROM `" . $_SESSION['sess_table'] . "` ORDER by ID ASC";
  
  if ($result = $mysqli-&gt;query($query)) { 
  
      $objPHPExcel = new PHPExcel();
      $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle($excelTitle);
  
      $headingsrow = $result-&gt;fetch_assoc();
      $headings = array_keys($headingsrow);
  
      //COLUMN NAMES
      $rowNumber = 1; 
      $col = 'A'; 
      foreach($headings as $heading) { 
  
          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($col.$rowNumber,$heading); 
          $col++;
  
      } 
  
      //RESULTS
      $rowNumber = 3;
      while ($row = $result-&gt;fetch_row()) { 
  
          $col = 'A'; 
          foreach($row as $key =&gt; $cell) { 
  
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($col.$rowNumber,$cell); 
              $col++;
  
         } 
  
         $rowNumber++;
  
      } 
  
      $objPHPExcel-&gt;getActiveSheet()-&gt;freezePane('A2'); 
  
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
  
      header('Content-Type: application/vnd.ms-excel'); 
      header('Content-Disposition: attachment;filename="' . $excelFilename . '.xls"'); 
      header('Cache-Control: max-age=0'); 
  
      $objWriter-&gt;save('php://output'); 
      exit(); 
  
  }
  </code></pre>