给你一个导出到Excel表的例子,不知道会不会对你有帮助。 <?php $mylink=mysql_connect("IP","登录名","密码"); mysql_select_db("数据库名",$mylink);Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Content-type:application/vnd.ms-excel"); Header("Content-Disposition:attachment;filename=export_excel_zsc.xls"); echo $province.'省'; if($province=='全部'){ $pro=" and 1=1 "; } else{ $pro=" and prov='".$province."'"; } //存储显示的个数 $coun=10; $date_ls=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from']; $date_from=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 00:00:00'; $date_to=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 23:59:59'; $ywh=$_POST['ywh']; if($ywh=='全部'){ $ywh_tj=" 1=1 "; $ls='所有'; } else{ $ywh_tj=" SpNum='".$ywh."'"; $ls=$ywh; } $tx=$date_ls.'('.$ls.')业务总时长统计'; echo $tx."\n\n";//-------------输出业务名 $sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc"; $result_output=mysql_query($sql_output,$mylink); if(mysql_num_rows($result_output)>0){ $q=0; echo "业务号:"."\t"; while($array_yh=mysql_fetch_array($result_output)){ $ch_sec=round($array_yh['a']/60,2); echo $array_yh['SpNum']."业务"."\t"; } echo "\n"; $sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc"; $result_output=mysql_query($sql_output,$mylink); if(mysql_num_rows($result_output)>0){ $q=0; echo "分钟:"."\t"; while($array_yh=mysql_fetch_array($result_output)){ $ch_sec=round($array_yh['a']/60,2); //$array_ls[$q][]=$ch_sec; //$array_pro[$q]=$array_yh['SpNum']."(".$ch_sec."分钟)"; $q=$q+1; echo round($array_yh['a']/60,2)."\t"; } } } else{ echo "没有符合的记录!"; } ?>
<?php
$mylink=mysql_connect("IP","登录名","密码");
mysql_select_db("数据库名",$mylink);Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=export_excel_zsc.xls");
echo $province.'省';
if($province=='全部'){
$pro=" and 1=1 ";
}
else{
$pro=" and prov='".$province."'";
}
//存储显示的个数
$coun=10;
$date_ls=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'];
$date_from=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 00:00:00';
$date_to=$_POST['year_from']."-".$_POST['month_from']."-".$_POST['date_from'].' 23:59:59';
$ywh=$_POST['ywh'];
if($ywh=='全部'){
$ywh_tj=" 1=1 ";
$ls='所有';
}
else{
$ywh_tj=" SpNum='".$ywh."'";
$ls=$ywh;
}
$tx=$date_ls.'('.$ls.')业务总时长统计';
echo $tx."\n\n";//-------------输出业务名
$sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc";
$result_output=mysql_query($sql_output,$mylink);
if(mysql_num_rows($result_output)>0){
$q=0;
echo "业务号:"."\t";
while($array_yh=mysql_fetch_array($result_output)){
$ch_sec=round($array_yh['a']/60,2);
echo $array_yh['SpNum']."业务"."\t"; }
echo "\n";
$sql_output="select sum(CountTime) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and ".$ywh_tj." and SpNum<>''".$pro." group by SpNum order by a desc";
$result_output=mysql_query($sql_output,$mylink);
if(mysql_num_rows($result_output)>0){
$q=0;
echo "分钟:"."\t";
while($array_yh=mysql_fetch_array($result_output)){
$ch_sec=round($array_yh['a']/60,2);
//$array_ls[$q][]=$ch_sec;
//$array_pro[$q]=$array_yh['SpNum']."(".$ch_sec."分钟)";
$q=$q+1;
echo round($array_yh['a']/60,2)."\t"; }
}
}
else{
echo "没有符合的记录!";
}
?>
首先感谢你的帮助。
你的程序大至上能读懂,关键是
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=export_excel_zsc.xls");
这4句不太明白,能否详细解释下。不胜感激!
但现在问题还没有解决,是我太菜了 :(
那位给出较具体的代码,或较明朗的思路,或相似的程序!