0

我的目标是创建一个页面,单击按钮后,我可以下载CSV包含特定结果的文件SQL Statement

这是我的按钮:

<?php
if (Env::value('profile')){
echo "<form action='/profiles/?s=".$sys->id."&profile=".$_GET["profile"]."&submit=true' method='get' class='asholder' enctype=\"multipart/form-data\">";
    echo "<input type=\"hidden\" name=\"sys\" value=\"".$sys->id."\" />"; 
    echo "<input type=\"hidden\" name=\"profile\" value=\"".$_GET["profile"]."\" />";
    echo "<input type='submit' name='submit' class=\"button\" value='Generate CSV'>";
echo "</form>";
}
?>

这是我的处理程序:

if (isset($_GET['submit'])){

    ob_end_clean();
    $q11="select * from profile";

    dump_csv($db, $q11, 'profile');

}

这是我应该创建 CSV 文件的方法:

function csv_field($s)
{
    return str_replace('"', '""', str_replace("\r","\n", iconv('UTF-8', 'Windows-1250', $s)));
}

function dump_csv($db, $q, $fname)
{
    header('Content-type: text/csv');
    header("Content-Disposition: attachment; filename=\"$fname.csv\"");
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public'); 

    foreach ($db->query($q)->fetchall(PDO::FETCH_ASSOC) as $row) {

        if (!$first_row++) {
            foreach ($row as $key => $value)
                echo csv_field($key).";";
            echo "\n";
        }

        foreach ($row as $key => $value)
            echo csv_field($value).";";
        echo "\n";

        //var_dump($row);
        //exit;
    }
}

是的,我ob_start();在页面的开头确实有。

问题是,而不是只有查询结果的表:select * from profileHTML在我的CSV.

谁能指出我在哪里做错了?

电流输出:

<form action='/?page=profile' method='post' class='asholder'>   

<table class='list questionaire'>   
<tr class='tabledesc'><th colspan='3'>person</th></tr>  

<tr class='columndesc'> 
"   <td style='width: 170px"    '>name</td>
"   <td style='width: 224px"    '>mith</td><td>
"   <div class='hint'>enter the name<br />" 
"   and role of person</b></div>"   
"   </td>"  
</tr>   
</table>    
4

0 回答 0