为什么我在我的MySQL导出为CSV的HTML? [英] Why am I getting HTML in my MySQL export to CSV?

查看:185
本文介绍了为什么我在我的MySQL导出为CSV的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题以前被问过,但是我遇到了一个问题。

I know this question has been asked before, but I ran into a problem.

奇怪的是,当我执行这个函数时,它包括页面的html

Oddly enough, when I execute this function, it includes the html of the page that the link you select to execute the function.

function exportCSV($table) {
    $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;
}

有人知道为什么会在csv文件中包含HTML?
alt text http://i35.tinypic.com/16i9oxi.jpg

Does anyone know why it would include the HTML in the csv file? alt text http://i35.tinypic.com/16i9oxi.jpg

推荐答案

我的猜测是,你有一些类型的模板生成相同的HTML页眉和页脚,请求。有时在调用exportCSV函数之前,会生成标题。

My guess is that you've got some sort of template that generates the same HTML header and footer regardless of the page that is requested. Sometime before the exportCSV function is called, the header is generated.

你不会显示输出的底部,但我敢打赌页脚也在那里,因为我怀疑流控制将继续到该代码后,函数退出。

You don't show the bottom of the output, but I'll bet the footer is there too, since I suspect the flow control will continue on to that code after the function exits.

这篇关于为什么我在我的MySQL导出为CSV的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆