开发者

My PHP Code appears in exported CSV document

I am now getting acquinted with exporting documents as CSV. But I am running into problems.

Once I introduce the CSV header into the code any subsequent PHP appears in the exported CSV documents instead of the information I wanted.

Please assist me with this.

header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=".$_GET['docname'].".csv");

//the php for getting the info
mysql_connect("localhost","root", "");
mysql_select_db("mydb");    

//CSV Processing
    $sql_csv = mysql_query($query); 
    $tCount = mysql_num_fields($sql_csv);

    //the first line is for the column names
    for($i=0; $i<=($tCount-1); $i++)
    {
        if(mysql_field_name($tColumns,$i)!='')
        {
            echo ucfirst(mys开发者_运维技巧ql_field_name($tColumns,$i)).',\n'; 
        }
    }

    while($row = mysql_fetch_row($sql_csv)) 
    {
        echo '"' . stripslashes(implode('","',$row)) . "\"\n";
    }

    exit;


Looks to me like you are missing the opening <?php tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜