exporting a table to a csv using mysqli and array
Hi there, I an attempting to export a field name from a table to a .csv file, however I get the following error inside the .csv file:
<b>Fatal error</b>: Call to a member function atEnd() on array in <b>C:\xampp\htdocs\armadillo\admin\newsletter-export.php</b> on line <b>18</b><br />
here is my code:
<?php require_once('../Connections/ecartdb.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php
$rsNewsletter = new WA_MySQLi_RS("rsNewsletter",$ecartdb,1);
$rsNewsletter->setQuery("SELECT NewsLetterEmail FROM newsletter WHERE NewsLetterOptIn = 1");
$rsNewsletter->execute();
$rsNewsletter = array();
?>
<?php
$filename = "emails.csv";
$fp = fopen('php://output', 'w');
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
while(!$rsNewsletter->atEnd()) {
fputcsv($fp, $rsNewsletter[0]);
$rsNewsletter->moveNext();
}
$rsNewsletter->moveFirst(); //return RS to first record
exit;
?>
Chris