case "9":
// create csv
$sql = "SELECT *
FROM ".$prefix."subscribers";
$results = $modx->db->query($sql);
$out = '';
$fields = $sql = "SHOW columns From ".$prefix."subscribers";
$columns = 12;
// Put the name of all fields
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($results, $i);
$out .= '"'.$l.'",';
}
$out .="\r\n";
// Add all values in the table
while ($l = mysql_fetch_array($results)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
}
$out .="\r\n";
}
// Open file export.csv.
$f = fopen ('export.csv','w');
// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="export.csv"');
readfile('export.csv');
break;
case "9":
// create csv
$sql = "SELECT *
FROM ".$prefix."subscribers";
$results = $modx->db->query($sql);
$out = '';
$fields = $sql = "SHOW columns From ".$prefix."subscribers";
$columns = 12;
// Put the name of all fields
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($results, $i);
$out .= '"'.$l.'",
';
}
//$out .="\r\n";
// Add all values in the table
while ($l = mysql_fetch_array($results)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",
';
}
//$out .="\r\n";
}
// Open file export.csv.
$f = fopen ('export.csv','w');
// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="export.csv"');
readfile('export.csv');
break;Koops Mailinglist - © 2006 Admin Menu Home | Send Mail | Subscribers | mailLabel1 | Add Subscriber "id","email","date","yourName","address1","address2","city","state","zip","country","phone","fax",/n"656","[email protected]","2010-06-26 12:13:35","","","","","","","","","", "78","[email protected]","2010-06-21 04:29:34","aaaaaaaaa","","","","","","","","", "79","[email protected]","2010-06-21 04:30:04","aaaaaaaaa","","","","","","","","", "80","","2010-06-21 04:30:41","aaaaaaaaaaa","","","","","","","","",
The header code is creating a html page with the first line of the page then with the csv code. Here is a short listing. I don’t know if that make a difference. At some point I need to get rid of the header and just have the first row be the field/column names followed by the csv.
chr(13) . chr(10)