$output lists only one record
I have the following code in a php file for exporting data to a csv file.
<?php require_once('../connections/PaSiteGuide.php'); ?>
<?php
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=BOP.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('ID','Common Name', 'Scientific Name', 'Breeds', 'Abundance', 'Occurrence', 'Seasonal Status','AOU_Order','AOU Supplement'));
// fetch the data
mysqli_select_db($conn, $database_PaSiteGuide);
$query_rsrows = sprintf('SELECT birdsofpa.ID, birdsofpa.CommonName, birdsofpa.SciName, birdsofpa.Breeding, birdsofpa.Abundance, birdsofpa.Occurrence, birdsofpa.SeasonalStatus,
aou_list.AOU_Order, aou_list.Updated FROM birdsofpa, aou_list WHERE birdsofpa.ID = aou_list.SPNO ORDER BY aou_list.AOU_Order ASC');
$rows = mysqli_query($conn, $query_rsrows) or die(mysqli_connect_error());
$row_rsrows = mysqli_fetch_assoc($rows);
$totalRows_rsrows = mysqli_num_rows($rows);
// loop over the rows, outputting them
while ($rows = mysqli_fetch_assoc($rows)) fputcsv($output, $rows);
?>
<?php
mysqli_free_result($rows);
?>
It outputs the file, but only the column titles and one row of data ( and the row it puts out is not the first row based on the ORDER BY specified).
So how do I make it do all of the rows and in the correct order?
