<?php
$list array
(
&39;位置&39;,&39;单元&39;,&39;房间&39;,&39;学号&39;,&39;姓名&39;,&39;性别&39;,&39;专业&39;
);
//$file fopen("contacts.csv","a");
header(&39;Content-Type: application/vnd.ms-excel;charsetgb2312&39;);
header(&39;Content-Disposition: attachment;filename&39;.date("YmdHis").".csv");
header(&39;Cache-Control: max-age0&39;);
// 打开PHP文件句柄,php://output 表示直接输出到浏览器
$fp fopen(&39;php://output&39;, &39;a&39;);
foreach ($list as $key>$val)
{
$list[$key] $val;
}
fputcsv($fp,$list);
//explode(&39;,&39;,$line)
$con mysql_connect("localhost","root","admin");
mysql_select_db("php_jquery_example");
$sql "select event_id, event_title, event_desc,event_start, event_end from events";
$result mysql_query($sql);
while($row mysql_fetch_array($result) ){
$list2 array($row[0],$row[1],$row[2],$row[3],$row[4]);
foreach($list2 as $k>$val){
$list2[$k] $val;
}
fputcsv($fp,$list2);
unset($list2);
}
fclose($fp);
mysql_close();
?>