<?php$result = mysql_query('select * from 表名');
$count = mysql_num_fields($result);for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i)."\t";
}while($row = mysql_fetch_row($result)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{ $value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
} $data = str_replace("\r", "", $data);if ($data == "") {
$data = "\nno matching records found\n";
}header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");echo $header."\n".$data; ?>
$count = mysql_num_fields($result);for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i)."\t";
}while($row = mysql_fetch_row($result)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{ $value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
} $data = str_replace("\r", "", $data);if ($data == "") {
$data = "\nno matching records found\n";
}header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");echo $header."\n".$data; ?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货