Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-01-08 21:27:01

maxk
Member
Registered: 2010-02-17
Posts: 11

Exporting table data to csv

This is my first plugin attempt, so it is quite simple, I think. I have a separate table in my database called applications. It contains data from application forms completed online. Name, address, etc.

My admin side plugin has, three actions/steps, ( list, delete, and download as csv).

I have it all worked out, except on the csv part, I am getting extra html data written to my csv file. It is the footer of the textpattern admin area. (The logo, textpattern 4.4.1, my username, ending body and html tags.

How do I prevent this html data being written to my csv file.

here is my step function that writes to csv file.

function zmk_admin_db_download() {
function query_to_csv($filename) {

$result = safe_rows_start(‘*’, ‘applications’, 1);

// send response headers to the browser
header( ‘Content-Type: text/csv’ );
header( ‘Content-Disposition: attachment;filename=’.$filename);
$fp = fopen(‘php://output’, ‘w’);
$headers = array (‘id’, ‘last_name’);
fputcsv($fp, $headers);
while ($r = nextRow($result)) {
fputcsv($fp, $r);
}
fclose($fp);
}
$date = date(‘Y-m-d’);
$filename = ‘tma-apps’ . $date;
query_to_csv($filename);
}

Just figured out to add a die(); statement before fclose, and it works, thanks ied_plugin_composer

Last edited by maxk (2012-01-08 21:40:23)

Offline

Board footer

Powered by FluxBB