したがって、完全なテーブルを CSV ファイルに単純にエクスポートする方法について他の提案を提供し始める前に、最初に述べさせてください。ブラウザ shabaz からダウンロードします)。
私は実際に、複数のテーブルからエクスポートするコンテンツを作成したいと考えています。とはいえ、私は現在、ブラウザーを介してエクスポートとダウンロードを機能させようとしているだけです。
私はこのコードをオンラインの例から入手しましたが、現在起こっていることは、単にデータをブラウザに出力しているだけです。
ここに私がテストしている私のコードがあります:
$result = mysql_query("SELECT * FROM results_tb") or die(mysql_error());
// I hard-code the column names so I can capitalize, add spaces, etc.
$fields = '"User ID","Test_id","score %","Time taken"'."\n";
// Iterate through the rows of data
while ($row = mysql_fetch_assoc($result))
{
//echo $row['user_id'];
$fields .= '"'.$row['user_id'].'","'.$row['test_id'].'","'.$row['score'].'","'.$row['time_elapsed'].'"'."\n";
}
// Set our headers
header('Content-type: text/csv');
// To display data in-browser, change the header below to:
// header("Content-Disposition: inline");
header("Content-Disposition: attachment; filename=event_registrations.csv");
// Output our data
echo $fields;
この例はパンツだと思いますので、誰かがこれを行う方法を説明してもらえますか?
どうもありがとう:D
私のヘッダー応答はfirebug-Liteでキャッチされました:
Date Wed, 18 May 2011 14:15:18 GMT
X-Powered-By PHP/5.1.6
Content-disposition attachment;filename=MyVerySpecial.csv
Connection close
Content-Length 992
Server Apache/2.2.3 (Red Hat)
Content-Type text/csv