php匯出資料到csv檔

來源:互聯網
上載者:User
關鍵字 網路程式設計 PHP教程

php教程匯出資料到csv檔
include(".. /admin/inc/inc.php");
$times = time();
$filename = $times.". csv";
$a = "連絡人,聯繫電話,社區,所需材料,備註,申請時間 n";
$days = postget("days");
$mktime = daystomktime($days);
$sql = "select * from  tugou where ($times-times)<$mktime";
$db = new db();
$result = $db->query( $sql );
$rs = $db->fetch($result,0);
foreach($rs as $v=>$vv)
{
$a.=$vv['name'].','. $vv['mo'].",". $vv['comm'].",".

commbox($vv['cbox']).",";
$a.="".$vv['bak'].",". date('y-m-d',$vv['times'])." rn

";
}
echo $a;
$hod = fopen ($filename,"w+");
if( fwrite($hod,$a) )
{
echo "生成檔成功,點擊<a href=$filename target=_blank>下載excel

文檔</a>";
}

function daystomktime($days)
{
switch( $days )
{
case 1:
$t = 86400;
break;
case 7:
$t = 86400*7;
break;
case 30:
$t = 86400*30;
break;
case 90:
$t = 86400*90;
break;
case 2048:
$t = 86400*2048;
break;
}
return $t;
}

function commbox( $ars )
 {
  if( trim( $ars ) == '' )
  {
   return '&nbs p;';
  }
 
  $array = include("tugou.php");
  $tmp = explode(',',$ars);
  $str ='';
  ; if( $tmp )
  {
   foreach( $tmp as $c )
   {
   $str .= $array[intval($ c)].'|';
   }
  }
  return $str;
 }
 
/*
 結構
 create table if not exists `tugou` (
  `id` int(8) not null auto_increm ent,
  `name` Varchar(20) default null comment '名字',
  `mo` Varchar(20) default null comment '手機',
& nbsp; `comm` Varchar(100) default null,
  `bak` Varchar(500) default null comment '備份',
  `cbox` Varchar(500) default null comment '類型',
  `times` int(4) default null,
  `ip` Varchar(20) default null,
  pr imary key  (`id`)
) engine=innodb  default charset=utf8 auto_increment=8 ;
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.