如何修复警告:无法修改标头信息

时间:2013-03-16 09:44:11

标签: php sql

我有这个代码从mysql导出到excell在wordpress我用链接

调用这个文件
    <?php include("header.php"); 

    $table = 'driver_detail';
    $file = 'export';

    $result = mysql_query("SHOW COLUMNS FROM ".$table."");
    $i = 0;
    if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
    $csv_output .= $row['Field']."; ";
    $i++;
    }
    }
    $csv_output .= "\n";
    $values = mysql_query("SELECT * FROM ".$table."");
    while ($rowr = mysql_fetch_row($values)) {
    for ($j=0;$j<$i;$j++) {
    $csv_output .= $rowr[$j]."; ";
    }
    $csv_output .= "\n";
    }

    $filename = $file."_".date("Y-m-d_H-i",time());
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$filename.".csv");
    print $csv_output;
    exit;
    ?>

但我有这个错误..如何解决这个问题

 Warning: Cannot modify header information - headers already sent by (output started at /home5/revoluv0/public_html/proj/autobodyparts/get-details/header.php:3) in /home5/revoluv0/public_html/proj/autobodyparts/get-details/export-driver.php on line 24

1 个答案:

答案 0 :(得分:0)

在标题之前打印了一些内容,即使是一个空格也会导致此问题。

相关问题