php导出mysql成cvs execel表

呵呵,下面代码有一点乱啊,是我在测试时做的,php
mysql日期计算代码[datediff]也是我今天需要时才来试的喽.下面看看代码

<?php
include_once(dirname(__FILE__).’../../Inc/Conn.php’);
include_once(dirname(__FILE__).’../../photo/Inc/function.php’);
$Date = date(“Y-m-d”);
$Filename = $Date.’_’.date(“h_i_s”).”.csv”;

function a($d){$Date_1=date(Y-m-d);$Date_2=$d;

$a = “帐号,邮箱,性别,宝宝出生日期,省份,真实姓名,邮编,手机,地址 rn”;
header(“Content-type:application/vnd.ms-excel”);
header(“Content-Disposition:filename=”.$Filename);
$Sql = “Select * from oy_use”;
$Result = mysql_query($Sql) or die(mysql_error());
  while($rs = mysql_fetch_array($Result) ){
   // if(get_days($rs[‘m_澳门新葡萄京娱乐场,time’])<= $Table ){
   $a.=$rs[‘User_Name’].’,’.
$rs[‘User_Mail’].”,”.($rs[‘User_Baby_Sex’]?’男’:’女’).”,”.
$rs[‘User_Baby_Birth’].”,”;
   $a.=””.$rs[‘sheng’].”,”.
$rs[‘User_rname’].”,”.$rs[‘User_Zip’].”,”.$rs[‘User_Hand’].”,”.$rs[‘User_Address’].”
rn “;
 //  }
  } 
  echo $a;

$Date_List_a1=explode(-,$Date_1);
$Date_List_a2=explode(-,$Date_2);

 
    
function get_days($base){

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

 $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),'<br>’;
 return round(($d1-$d2)/3600/24);

$d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);

}
?>

return round(($d1-$d2)/3600/24); }

//echo $Days;

$d=date(Y-m-d H:i:s);$sql =Select * from wk_member where
m_ip=’127.0.0.1′ and datediff(m_dtime,’$d’)=0 ;$result
=mysql_query($sql) or
die(mysql_error());if(mysql_num_rows($result)5){echo ‘t’;}while ($rs
=mysql_fetch_array($result) ){echo $rs[‘id’];echo ‘br’;}

本站原创转载请注明

发表评论

电子邮件地址不会被公开。 必填项已用*标注