while($data_array=mysql_fetch_array($result)){
$data[$i]=$data_array;
$i++;
}
$title=array("game_name","des","url","add_time");
$keys=array("game_name","des","url","add_time");
exportToExcel($data,'aa.xls',$title,$keys);
function exportToExcel($data,$filename,$title,$keys){ //$keys為data中要導出的數據列
header('Content-type: text/cvs');
header("Content-Disposition: attachment; filename=\"$filename\"");
$top = '數據導出時間:'.date('Y-m-d H:i:s');
$table = '
';
$table .= ' | ';
foreach($title as $value){
$table .= ''.$value.' | '; //列標題
}
$table .= '';
$i =1;
foreach($data as $value){
$table .= ''.$i.' | '; //序號
foreach($keys as $key){ //數據內容
$table .= ''.$value[$key].' | ';
}
$table .= '
';
$i++;
}
$table .= '
';
$top = iconv('utf-8','gbk',$top);
$table = iconv('utf-8','gbk',$table);
echo $top;
echo $table;
exit;
}