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 profile全体を.HTMLCSV

誰かが私が間違いを犯している場所を教えてもらえますか?

現在の出力:

<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