Hi all,
I am having a problem with my script where when i try to export data from my database to a csv file it appends the html of the page to the bottom of the CSV file. It gives me all the necessary values I need, but with annoying html of the page at the end. I am not sure how to get past this issue so some tips would be appreciated. The code is as follows.
PHP Code:
case "csv":
$main .= "<h1>Export to CSV Format</h1>";
$main .= '<div class="orange_container">';
$sql = "SELECT id,date,fullname,street,city,zip,phone,email,club FROM registration";
$results = $db->qarray($sql);
//
// send response headers to the browser
// following headers instruct the browser to treat the data as a csv file called export.csv
//
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename=export.csv' );
//
// output header row (if atleast one row exists)
//
if($results != false)
{
foreach($results as $result)
{
$fields = array($result['id'],$result['date'],$result['fullname'],$result['street'],$result['city'],$result['zip'],$result['phone'],$result['email'],$result['club']);
echocsv($fields);
}
$main .= "CSV File created!";
}
else
{
$main .= '<div id="error">Failed to create CSV File!</div>';
}
$main .= '</div>';
break;



Reply With Quote

Bookmarks