欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php 导出csv文件程序

程序员文章站 2022-03-19 21:54:22
...
php 导出csv文件程序


$Date = date("Y-m-d");
$Filename = $Date.'_'.date("h_i_s").".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:'';
$Auto = isset($_POST['d'])?$_POST['d']:'';
if( is_numeric($Auto ) ){
$Table =$Auto;
}
$a = "用户名,真实姓名,联系方式,联系QQ,联系地址,邮箱地址 rn";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
$Sql = "Select * from gx_member";
$Result = mysql_query($Sql) or die(mysql_error());
while($rs = mysql_fetch_array($Result) ){
if(get_days($rs['m_time']) $a.=$rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",";
$a.="".$rs['m_address'].",". $rs['m_mail']." rn ";
}
}
echo $a;

function get_days($base){

$Date_1=date("Y-m-d");//格式也可以是:$Date_1="2003-6-25 23:29:14";

$Date_2=substr($base,0,10);

$Date_List_a1=explode("-",$Date_1);

$Date_List_a2=explode("-",$Date_2);
//print_r($Date_List_a2);

$d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);

$d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);
//echo round(($d1-$d2)/3600/24),'
';
return round(($d1-$d2)/3600/24);


}
?>
本站原创转载请注明 www.111cn.cn/phper/php.html